effect icon indicating copy to clipboard operation
effect copied to clipboard

feat: expose raw sqlite client in `sql-sqlite-bun` and `sql-sqlite-node`

Open Leka74 opened this issue 4 months ago • 2 comments

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

Leka74 avatar Aug 26 '25 10:08 Leka74

⚠️ 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

changeset-bot[bot] avatar Aug 26 '25 10:08 changeset-bot[bot]

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.

tim-smart avatar Sep 02 '25 21:09 tim-smart