Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add sqlite storage #21

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

rajeshg
Copy link
Contributor

@rajeshg rajeshg commented Dec 10, 2024

Adds sqlite storage option using libsql. better-sqlite3 doesn't play well with bun.

Fixes #11

@calirvine
Copy link

I think an improvement here would be to make the table name configurable, or make it something much less likely to have a collision __openauth__kv_storage

Copy link

changeset-bot bot commented Dec 10, 2024

🦋 Changeset detected

Latest commit: bd9ce7b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@openauthjs/openauth Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@thdxr
Copy link
Contributor

thdxr commented Dec 10, 2024

made some changes but i think TTL is not respected? get/scan should not return values that have expired (maybe worth deleting those too on read)

@rajeshg
Copy link
Contributor Author

rajeshg commented Dec 11, 2024

Added one liner to cleanup expired rows on get/scan. Do we need something similar for memory storage as well to cleanup expired values?

@thdxr
Copy link
Contributor

thdxr commented Dec 11, 2024

sorry i should have been more explicit

i don't think we should run a cleanup on every call - i meant when we do a get we should check if it's expired and delete it and not return it

similarly with scan, if we come across an expired value we should delete it

it's not necessary so i'll merge even without that just as long as the adapter is not returning expired values

@thdxr
Copy link
Contributor

thdxr commented Dec 11, 2024

btw i just pushed a basic set of tests, maybe can try them with the sql adapter

const TABLE_NAME = input?.tableName ?? "__openauth__kv_storage";

db.exec(
`CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (key TEXT PRIMARY KEY, value TEXT, expiry INTEGER)`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expiry is a separate column instead of being part of the value, as it's relatively easier to query.

let storage = SQLiteStorage();

beforeEach(async () => {
storage = SQLiteStorage();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty much the same as memory storage test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQLite Support
3 participants