tndrle / node-sqlite3-wasm

WebAssembly port of SQLite3 for Node.js with file system access
MIT License
63 stars 9 forks source link

Drizzle support #59

Open ido-pluto opened 9 months ago

ido-pluto commented 9 months ago

Thank you! Amazing work! No one has done this until now, and using SQLite with node was a headache.

I was wondering if you could add official support for the Drizzle ORM.

Drizzle is a new, popular yet simple ORM https://orm.drizzle.team/

Your API is very similar to better-sqlite3, so it may be already fully supported. I am sure that if you mention that many people will know and support your work.

Good Luck :)

giladgd commented 9 months ago

Thank you for your amazing work 💞

I also want to use this awesome library and Drizzle support is the missing piece I need for that. Adding support for Drizzle and getting mentioned in their docs will surely make this library extremely popular.

better-sqlite3 is actually not really better because of its dependence on internal v8 api that requires native binaries for every and each node version and architecture, which fails to install quite often and causes frequent headaches. node-sqlite3-wasm solves this problem from its root while providing elegant and efficient alternative. It’s the alternative I was looking for for a long time.

tndrle commented 9 months ago

Hi, thanks for the suggestion. Is there any documentation about what is required for a backend to be compatible with Drizzle?

giladgd commented 9 months ago

I couldn't find any documentation explaining how to add support for a new backend, but I've looked at the source code of Drizzle and I found that all of the code of the better-sqlite3 integration is in this directory, so I think adding support for node-sqlite3-wasm would require creating another directory for the node-sqlite3-wasm integration and implementing something similar there.

ido-pluto commented 9 months ago

The bun's implementation may be more similar to the current API than better-sqlite3's. https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/bun-sqlite/session.ts

ido-pluto commented 9 months ago

I created a wrapper around node-sqlite3-wasm to polyfill bun's implementation of Database and Statement. But I get an error saying the database is locked

SQLite3Error: database is locked
    at Sqlite3Polyfill._handleError (/node_modules/node-sqlite3-wasm/dist/node-sqlite3-wasm.js:8:5979)
    at new Statement (/node_modules/node-sqlite3-wasm/dist/node-sqlite3-wasm.js:8:6099)
    at Sqlite3Polyfill.prepare (/node_modules/node-sqlite3-wasm/dist/node-sqlite3-wasm.js:8:5363)

Do you know what can cause this?

tndrle commented 9 months ago

Maybe it's a problem with unfinalized prepared statements. node-sqlite3-wasm requires manually finalizing prepared statements...