Skip to content

Conversation

himself65
Copy link
Member

@himself65 himself65 commented Aug 7, 2025

I'm a Node.js SQLite WG member, so I'm happy to integrate this into better-auth. Even though it's not stable yet but it's okay to do sth like testing and small demo

Document: https://nodejs.org/docs/v22.18.0/api/sqlite.html#sqlite


Summary by cubic

Added support for the experimental Node.js built-in SQLite driver (node:sqlite) in Better Auth, allowing users to connect using DatabaseSync. Updated documentation and added tests for the new dialect.

  • New Features
  • Implemented a NodeSqliteDialect for Kysely to support node:sqlite.
  • Added integration tests to verify compatibility with Better Auth.
  • Updated docs to show usage examples for both better-sqlite3 and node:sqlite.

@himself65 himself65 requested a review from Bekacru as a code owner August 7, 2025 23:29
Copy link

vercel bot commented Aug 7, 2025

@himself65 is attempting to deploy a commit to the better-auth Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

pkg-pr-new bot commented Aug 7, 2025

Open in StackBlitz

better-auth

npm i https://pkg.pr.new/better-auth/better-auth@3869

@better-auth/cli

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/cli@3869

@better-auth/expo

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/expo@3869

@better-auth/sso

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/sso@3869

@better-auth/stripe

npm i https://pkg.pr.new/better-auth/better-auth/@better-auth/stripe@3869

commit: 5c3cf61

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic analysis

5 issues found across 12 files • Review in cubic

React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.

isAutoIncrementing: col.name === autoIncrementCol,
hasDefaultValue: col.dflt_value != null,
})),
isView: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every table is incorrectly flagged as a view (isView: true) instead of being detected dynamically or defaulting to false.

Prompt for AI agents
Address the following comment on packages/better-auth/src/adapters/kysely-adapter/node-sqlite-dlalect.ts at line 255:

<comment>Every table is incorrectly flagged as a view (isView: true) instead of being detected dynamically or defaulting to false.</comment>

<file context>
@@ -0,0 +1,300 @@
+/**
+ * @see {@link https://nodejs.org/api/sqlite.html} - Node.js SQLite API documentation
+ */
+import {
+	Kysely,
+	CompiledQuery,
+	DEFAULT_MIGRATION_LOCK_TABLE,
+	DEFAULT_MIGRATION_TABLE,
+	sql,
</file context>
Suggested change
isView: true,
isView: false,

if ("fileControl" in db) {
return "sqlite";
}
if ("open" in db && "close" in db && "prepare" in db) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relying on the presence of an "open" method to detect a node:sqlite Database instance is unreliable – the DatabaseSync object returned by node:sqlite exposes close and prepare, but not open. Consequently, this condition will almost never be satisfied for real database objects, so the adapter will not be selected even when node:sqlite is actually used.

Prompt for AI agents
Address the following comment on packages/better-auth/src/adapters/kysely-adapter/dialect.ts at line 47:

<comment>Relying on the presence of an &quot;open&quot; method to detect a node:sqlite Database instance is unreliable – the DatabaseSync object returned by node:sqlite exposes `close` and `prepare`, but *not* `open`.  Consequently, this condition will almost never be satisfied for real database objects, so the adapter will not be selected even when node:sqlite is actually used.</comment>

<file context>
@@ -44,6 +44,9 @@ function getDatabaseType(
 	if (&quot;fileControl&quot; in db) {
 		return &quot;sqlite&quot;;
 	}
+	if (&quot;open&quot; in db &amp;&amp; &quot;close&quot; in db &amp;&amp; &quot;prepare&quot; in db) {
+		return &quot;sqlite&quot;;
+	}
</file context>

});
});

describe("better-auth adapter integration", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Async function passed to describe can cause unpredictable test ordering and race conditions; describe callbacks should be synchronous

Prompt for AI agents
Address the following comment on packages/better-auth/src/adapters/kysely-adapter/test/normal/node-sqlite-dialect.test.ts at line 196:

<comment>Async function passed to describe can cause unpredictable test ordering and race conditions; describe callbacks should be synchronous</comment>

<file context>
@@ -0,0 +1,260 @@
+import { DatabaseSync } from &quot;node:sqlite&quot;;
+import { describe, it, expect, beforeAll, afterAll } from &quot;vitest&quot;;
+import { Kysely, sql } from &quot;kysely&quot;;
+import { NodeSqliteDialect } from &quot;../../node-sqlite-dlalect&quot;;
+import { kyselyAdapter } from &quot;../../kysely-adapter&quot;;
+import { runAdapterTest } from &quot;../../../test&quot;;
+import { getMigrations } from &quot;../../../../db/get-migration&quot;;
+import type { BetterAuthOptions } from &quot;../../../../types&quot;;
+import merge from &quot;deepmerge&quot;;
</file context>

@Bekacru
Copy link
Contributor

Bekacru commented Aug 7, 2025

lets go

@himself65 himself65 force-pushed the himself65/2025/08/07/fix branch 5 times, most recently from b8bbd11 to cd93f65 Compare August 8, 2025 08:15
@himself65 himself65 force-pushed the himself65/2025/08/07/fix branch from e699806 to 00315e8 Compare August 8, 2025 20:29
# Conflicts:
#	examples/browser-extension-example/package.json
#	examples/nextjs-mcp/package.json
#	examples/tanstack-example/package.json
#	pnpm-lock.yaml
@himself65 himself65 requested a review from Bekacru August 12, 2025 20:52
Copy link

vercel bot commented Aug 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
better-auth-docs Ready Ready Preview Comment Aug 20, 2025 7:49pm

@himself65 himself65 merged commit fc8a25a into better-auth:canary Aug 20, 2025
3 of 5 checks passed
bartlomieju added a commit to denoland/deno that referenced this pull request Sep 8, 2025
Related:
nodejs/node@d1eabcb
Related: nodejs/node#59405
Related: better-auth/better-auth#3869
Related: oven-sh/bun#22109

Nowadays, there are tons of database packages, like sqlite3, sqlite,
better-sqlite, bun:sqlite... Checking the difference from them is pretty
hard.
instanceof is not good, since the developer will still need to import
the module, which is costly.
I think we should provide a symbol to distinguish different SQLite
classes, at least nodejs could make the first step.

---------

Signed-off-by: Alex Yang <[email protected]>
Co-authored-by: Bartek Iwańczuk <[email protected]>
Tango992 pushed a commit to Tango992/deno that referenced this pull request Sep 24, 2025
Related:
nodejs/node@d1eabcb
Related: nodejs/node#59405
Related: better-auth/better-auth#3869
Related: oven-sh/bun#22109

Nowadays, there are tons of database packages, like sqlite3, sqlite,
better-sqlite, bun:sqlite... Checking the difference from them is pretty
hard.
instanceof is not good, since the developer will still need to import
the module, which is costly.
I think we should provide a symbol to distinguish different SQLite
classes, at least nodejs could make the first step.

---------

Signed-off-by: Alex Yang <[email protected]>
Co-authored-by: Bartek Iwańczuk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants