drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

Add SQLite WASM driver support

Open AndriiSherman opened this issue 1 year ago ā€¢ 15 comments

AndriiSherman avatar Feb 28 '23 12:02 AndriiSherman

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 avatar Mar 08 '23 06:03 Azarattum

@Azarattum yes, we were looking into using official SQLite wasm

AndriiSherman avatar Mar 08 '23 09:03 AndriiSherman

Hi @AndriiSherman ā€“ any update on this? I can try to help if you need

jordanhboxer avatar Apr 29 '23 20:04 jordanhboxer

@AndriiSherman Would it be possible to know how this is going?

ShravanSunder avatar Aug 03 '23 14:08 ShravanSunder

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 avatar Aug 04 '23 01:08 DallasHoff

@DallasHoff do you have feature list for drizzle that your lib covers? Nice work, and nice docs too!

ShravanSunder avatar Aug 05 '23 16:08 ShravanSunder

@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.

DallasHoff avatar Aug 06 '23 03:08 DallasHoff

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 avatar Aug 10 '23 03:08 DallasHoff

@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.

sjunepark avatar Oct 10 '23 11:10 sjunepark

@AndriiSherman Just out of curiosity, was this deprioritised due to it being more complicated than expected or lack of interest?

AntonOfTheWoods avatar Dec 27 '23 01:12 AntonOfTheWoods

@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, like db.all(sql`SELECT * FROM foo`))?
  • is there an "official" way to handle prepared query finalization? Both cr-sqlite and wa-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?

Sheraff avatar Mar 30 '24 17:03 Sheraff

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 avatar Apr 07 '24 02:04 AntonOfTheWoods

@AntonOfTheWoods Be sure to give #1009 a thumbs up if you haven't already so that the maintainers know that there is interest.

DallasHoff avatar Apr 07 '24 15:04 DallasHoff

@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...

AntonOfTheWoods avatar Apr 07 '24 21:04 AntonOfTheWoods

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

zackify avatar May 11 '24 02:05 zackify