-
-
Notifications
You must be signed in to change notification settings - Fork 641
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
Add durable objects sqlite driver #3053
base: main
Are you sure you want to change the base?
Conversation
config?: string | Omit<MigrationConfig, 'migrationsFolder'>, | ||
) { | ||
db.dialect.migrate(migrations, db.session, { | ||
...(typeof config !== 'string' && config), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail, as the sqlite dialect uses BEGIN/COMMIT, which are not allowed on DO sqlite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why the sqlite dialect migrate function doesn't use transactions within... but I haven't spent any time looking into it. I assume there might be a legitimate reason I'm just not seeing.
config: SQLiteTransactionConfig = {}, | ||
): T { | ||
const tx = new DurableObjectSQLiteTransaction('sync', this.dialect, this, this.schema); | ||
this.run(sql.raw(`begin${config?.behavior ? ' ' + config.behavior : ''}`)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also fail. To do transactions, you have to use a function which is (so far) only documented on Discord:
this.ctx.storage.transactionSync(() => {...})
https://discord.com/channels/595317990191398933/773219443911819284/1292483777557172316
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @zwily! I hadn't gotten round to testing transactions yet. I've tested this API and it works perfectly. I also checked that it can be nested, and that works perfectly as well.
override transaction<T>(transaction: (tx: DurableObjectSQLiteTransaction<TFullSchema, TSchema>) => T): T { | ||
const savepointName = `sp${this.nestedIndex}`; | ||
const tx = new DurableObjectSQLiteTransaction('sync', this.dialect, this.session, this.schema, this.nestedIndex + 1); | ||
this.session.run(sql.raw(`savepoint ${savepointName}`)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Savepoints also don't work. Have to use the API above.
Cool - I updated my test app at https://github.com/zwily/test-drizzle-durable-objects to use the new migrate method. |
Hi @jmshal, great work so far! What is the current state of this? Do you need any help moving this forward? I'm currently also working with the Workers DO SQL API and doing everything "by hand", which is quite unsustainable ^^ |
Hi @constantins2001. When I left this - it was all working, minus migrations. I've asked for comments about how that should work. I have ideas, but other than tweeting generally about supporting DO SQLite if they got enough likes, the official Drizzle team has not shown any interest in this PR or issue. I'm happy to work on this issue further, but I don't want to waste any time if existing maintainers/the Drizzle team don't agree with the direction it takes. |
This PR adds initial support for the SQLite capabilities in Cloudflare Durable Objects.
See #3052 for more info.
This is my first contribution to Drizzle - so any pointers are much appreciated. Unfortunately I have limited time right now, but I can see what I can do.