drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.02k stars 608 forks source link

[FEATURE]: Durable Objects SQLite driver #3052

Open jmshal opened 2 weeks ago

jmshal commented 2 weeks ago

Describe what you want

It would be awesome to have a driver that supported the new SQLite capabilities of Durable Objects.

I have an initial driver implemented, but this is my first time contributing anything to Drizzle - so I'm creating this issue to get the discussion started. My initial implementation appears to work (I've only done minimal testing). I'll push a PR shortly.

As an aside - it appears that getting migrations working will take a bit more time and effort. I've omitted the migrator file from the driver on my fork. I was thinking that for the mean time (for my own use-case) I'll just create a CLI that takes the migrations directory and generates a JS/TS module that can be imported by a worker like normal. This way in the constructor of the Durable Object all you have to do is call the function it exports to run the migration logic. This logic will essentially be an inlined copy of all the migration steps, and a call to the base SQLite sync migration code? I'm thinking of publishing this myself, but would this kind of thing be suited in this repo? Perhaps part of drizzle-kit?

zwily commented 2 weeks ago

For migrations, I think adding an option to drizzle-kit to just dump out a .json file into the migrations directory would be enough. That's basically all I did in my test repo here: https://github.com/zwily/test-drizzle-durable-objects/blob/main/scripts/bundle-migrations.js

And then we would import that and call a migrate function in the DO constructor.