sqlight icon indicating copy to clipboard operation
sqlight copied to clipboard

Consider using `node:sqlite`

Open double-daruma opened this issue 4 months ago • 5 comments

Deno (and node.js) now have built in support for sqlite3 with the same module. The benefit of using this built in module is that real sqlite will be used whereas x/sqlite that is currently used has weaker consistency guarantees. This might also allow this gleam library to work on node.js.

double-daruma avatar Aug 12 '25 09:08 double-daruma

Could be good!

lpil avatar Aug 12 '25 11:08 lpil

Hello!
I’m currently developing a new JavaScript FFI for sqlight.

This FFI is compatible with the node:sqlite module for both Node.js and Deno, and all tests pass using the following commands.

gleam test --target javascript --runtime node
gleam test --target javascript --runtime deno

Since this FFI relies on the node:sqlite package for Node.js and Deno and introduces breaking changes, it only works with Node.js v22.5 or later and Deno v2.2 or later.

You can check out the code on this branch.
To use it, add the following configuration to your gleam.toml file:

[dependencies]
sqlight = { git = "https://github.com/Comamoca/sqlight", ref = "feature/node-sqlite" }

Comamoca avatar Oct 05 '25 19:10 Comamoca

Very cool! Would you like to make a PR?

I had a quick look at the code and there's a fairly serious bug in the numbered parameters bit- it can edit the content of strings within the SQL! select '?hello?';

lpil avatar Oct 06 '25 13:10 lpil

Thanks for pointing that out! I’ll fix the issue and open a PR over the weekend.

Comamoca avatar Oct 07 '25 00:10 Comamoca

I investigated the FFI bug over the weekend, and reached the following conclusions.

Regarding the substitution process of ? which caused the bug, this has been fixed in Node.js's node:sqlite, so I have removed the corresponding processing. Therefore, the bug should be resolved.

https://github.com/Comamoca/sqlight/commit/8a04d3f6bf92df40a51f10619ccd84a1bd1bd32e

As a result, the tests are currently failing in Deno, but this is because Deno has not yet incorporated the latest node:sqlite.

I plan to create a PR once I confirm that Deno has incorporated the latest node:sqlite. I will likely be able to submit the PR within the year.

Comamoca avatar Oct 12 '25 23:10 Comamoca