-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(bun): add bun sqlite support #71
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for you work! I will soon hand over this project to @penberg, so I will let him decide how to proceed. However, a few points regarding the PR:
- The Bun code and the tests are a copy-paste of the better-sqlite3 code and Jest tests with a few modifications. I don't think that this is sustainable; the Bun and better-sqlite3 clients might be able to share some code, and we should be able to use the same test code in both Node and Bun.
- If the Bun client cannot correctly implement
intMode: "bigint"
andexecuteMultiple()
, I think it would be better to throw an error rather than producing wrong results or errors at runtime.
Thanks for the review @honzasp, I will implement these changes.
|
Yes, there is no automatic formatter. Format the code as you see fit, preferably in a way that's not too different from the existing code :)
The npm lockfile is committed into the repo to make the testing in CI repeatable, so perhaps we should do the same for the Bun lockfile? (I have zero experience with Bun, but I assume that its lockfile works the same as the npm lockfile?)
Yes. Having two copy-pasted test suites wouldn't be acceptable for me. However, I will hand over this project to @penberg in a few days, and his opinion might be different :)
|
Thanks for the review @honzasp. I resolved all of our conversations. Please let me know if I missed anything.
To confirm that everything is working further, I deployed a fork of libsql-client-ts that I'm using with drizzle and bun https://www.npmjs.com/package/@hebilicious/libsql-client import { drizzle } from "drizzle-orm/libsql"
import { createClient } from "@hebilicious/libsql-client"
const url = process.env.DATABASE_URL ?? "file:drizzle/local.db"
const authToken = process.env.DATABASE_AUTH_TOKEN
console.log(`Connecting to ${url}...`)
export const client = createClient({ url, authToken })
export const db = drizzle(client) I have a few outstanding questions :
|
Hey @Hebilicious, please do add Bun to CI (otherwise we'll just end up breaking it) and also feel free to update the README. |
Hi @penberg, I will update this. Do you have any insight regarding the tests themselves ? I agree it's not ideal, I did it like this to avoid doing a major re-factor of the existing tests and to make sure bun:sqlite was working as intended. The bun:sqlite module has native code bindings that won't work with node, therefore we need to write the tests accordingly. Bun support for jest is still WIP (?), and to avoid issues and too much refactor in this PR, I went with the RY route. I'm interested in what @penberg has to say, but I think there's 3 options :
In the meantime this gives us confidence that the library is working. I personally think we should go with |
@Hebilicious I agree that we should keep Bun tests separate. Presumably in the future Bun gets compatible enough that the separate suite just becomes redundant and we'll switch to one suite. |
Btw Vercel tests were using an expired token, which is sorted now. For Cloudflare, there seems to be some issue with the Hrana remote protocol, so I disabled the tests for now 37382a7 Both unrelated to this PR of course |
@Hebilicious Btw, I switched from tursodatabase/libsql-js#10 (comment) Do we still need to support bun:sqlite driver after the switch to |
@penberg That's great ! For my use case, I would personally still prefer to use On a side note, I am a little bit worried about the potential confusion between Regarding the tests, I have a suggestion : Now that |
I've tested the |
return _createBunSqliteClient(config); | ||
} else { | ||
throw new LibsqlError( | ||
'The Bun client supports "file", "libsql:", "wss:", "ws:", "https:" and "http:" URLs, ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'The Bun client supports "file", "libsql:", "wss:", "ws:", "https:" and "http:" URLs, ' + | |
'The Bun client supports "file:", "libsql:", "wss:", "ws:", "https:" and "http:" URLs, ' + |
Resolves #70
This PR adds support for bun-sqlite. This allows the
bun:sqlite
driver to be used with Bun when using the file protocol.There is some difference in the implementation with
better-sqlite3
:info
returned bybetter-sqlite3
runbatch
under the hood.Additionally, I did not implemement any of the server related tests, as I believe this driver should only be used for local databases.
There's one outstanding question regarding the bun lockfile which I did not include, and whether we should bother taking care of both lockfiles (This can be done automatically by the CI)
Before moving forward I would appreciate a review 🙏🏽
TODO :