feat: expose raw sqlite client in `sql-sqlite-bun` and `sql-sqlite-node`
Type
- [ ] Refactor
- [x] Feature
- [ ] Bug Fix
- [ ] Optimization
- [ ] Documentation Update
Description
This PR is intended to expose the internal database client for sql-sqlite-bun and sql-sqlite-node packages. My primary reason for doing this was the need to feed the better-auth library with the raw database client, which currently is not available.
I think this can be afterwards added to the other sql packages.
Usage:
const sql = yield* SqliteClient.SqliteClient
const rawClient = yield* sql.rawClient
yield* Effect.sync(() => rawClient.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)"))
yield* Effect.sync(() => rawClient.exec("INSERT INTO test (name) VALUES ('hello')"))
const rows = yield* Effect.try(() => rawClient.prepare("SELECT * FROM test").all())
assert.deepStrictEqual(rows, [{ id: 1, name: "hello" }])
Or in my use-case:
const make = Effect.gen(function*() {
const sql = yield* SqliteClient.SqliteClient;
const rawClient = yield* sql.rawClient;
const auth = yield* Effect.try(() =>
betterAuth({
database: rawClient,
emailAndPassword: {
enabled: true,
},
}),
);
return BetterAuthClient.of(auth);
});
Related
- Related Issue N/A
- Closes N/A
⚠️ No Changeset found
Latest commit: 4fc5c2dea18c1fb0251502d397ad7c927b1e3ed0
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
A better approach is allowing a raw client to be passed in.
But I'm not sure about this, as currently the client is protected with a semaphore to ensure exclusive use during async transactions. Also, if we decide to change the underlying client it would be a breaking change.