drizzle-orm
drizzle-orm copied to clipboard
Add SQLite WASM driver support
Is this for the official SQLite wasm or for something like wa-sqlite (which from my understanding is currently superior to the official build)?
@Azarattum yes, we were looking into using official SQLite wasm
Hi @AndriiSherman ā any update on this? I can try to help if you need
@AndriiSherman Would it be possible to know how this is going?
Recently, I've been working on a library to make SQLite WASM easier to use, and I found that making it work as a driver for Drizzle was actually pretty easy. If you need this, I hope it helps you out: https://sqlocal.dallashoffman.com/drizzle/setup
For migrations, I've been looking into making a PR to Drizzle to add a version of their migrate
function that works on the frontend. It should be possible. I'll probably make an issue first just so the Drizzle guys have a chance to say "no thanks" or "we already have this halfway done" first. Hopefully there's interest from them.
@DallasHoff do you have feature list for drizzle that your lib covers? Nice work, and nice docs too!
@ShravanSunder Querying and anything else that you do through the main drizzle
function should work. It's just migrations that need work since Drizzle's migrate
function only works in Node.js, but everything else looks to work just fine in the browser. Drizzle handles the schema definition and query building stuff. It passes the raw SQL for the query to SQLocal acting as the driver, and SQLocal takes that, passes it to the SQLite WASM database, and returns any result data back to Drizzle. It's like any other driver except instead of communicating with a remote server running the database, the database is running in a web worker.
For migrations, I've been looking into making a PR to Drizzle to add a version of their
migrate
function that works on the frontend. It should be possible. I'll probably make an issue first just so the Drizzle guys have a chance to say "no thanks" or "we already have this halfway done" first. Hopefully there's interest from them.
Here's that issue for those interested: #1009
@DallasHoff I had a hard time setting up sqlite wasm, and had no idea I would stumble into such a project here. Will try it out thanks.
@AndriiSherman Just out of curiosity, was this deprioritised due to it being more complicated than expected or lack of interest?
@AndriiSherman I wrote an adapter for crsqlite-wasm
(from Vlcn https://vlcn.io/docs/cr-sqlite/intro). As far as I can tell, this seems to be working. It's heavily inspired from the better-sqlite3
and the libsql
adapters from this very repo.
Here's the published package for it: https://www.npmjs.com/package/drizzle-orm-crsqlite-wasm.
I have a few questions, of which you can answer between none and all (no worries, I know OSS is draining!):
- are there any plans to add support to wasm sqlite builds (crsqlite, wa-sqlite, or other)? I wasn't planning on writing a package and my hope is that it can become deprecated at some point.
- is there any way to bypass creating a
PreparedQuery
when running queries directly on the Session (without a query builder, likedb.all(sql`SELECT * FROM foo`)
)? - is there an "official" way to handle prepared query finalization? Both
cr-sqlite
andwa-sqlite
create "statement" objects on which we need to call.finalize()
at some point to avoid memory leaks. I ended up using the FinalizationRegistry to auto-finalize those queries, but I was curious whether there would be a more "standard" way in drizzle to do that. - does the code look exhaustive? Or am I missing some use-cases that wouldn't work with this adapter but would with any other?
There seem to be a lot of interest in generating hype but not much interest in making things useful. "Support" for pglite
has been added, which is still very much proof-of-concept/pre-alpha, which is also a browser-based db but still no examples on how this might actually be useful, given there is no way to make migrations happen.
@AntonOfTheWoods Be sure to give #1009 a thumbs up if you haven't already so that the maintainers know that there is interest.
@AntonOfTheWoods Be sure to give #1009 a thumbs up if you haven't already so that the maintainers know that there is interest.
@DallasHoff Unless I'm mistaken, none of the maintainers have even bothered to comment on that ticket, which seems to have garnered at least a modicum of interest. Not giving me much confidence in the health of the project ecosystem...
I saw a maintainer say it was on the roadmap last march, can someone at least respond from the drizzle team?
Iām going to sponsor them in hope of getting this issue looked at