On this page

Databases

SQLite

Integrate Entro Auth with SQLite.

SQLite is a lightweight, serverless, self-contained SQL database engine that is widely used for local data storage in applications. Read more here.

Example Usage

Entro Auth supports multiple SQLite drivers. Choose the one that best fits your environment:

The most popular and stable SQLite driver for Node.js:

auth.ts
import { entroAuth } from "@entro314labs/entro-auth";
import Database from "better-sqlite3";

export const auth = entroAuth({
  database: new Database("database.sqlite"),
});
Note

For more information, read Kysely's documentation to the SqliteDialect.

Node.js Built-in SQLite (Release Candidate)

Note

The node:sqlite module is a Release Candidate as of Node.js 24.15.0. It requires Node.js 22.5.0 or later and no longer requires the --experimental-sqlite flag since Node.js 22.13.0 / 23.4.0.

Starting from Node.js 22.5.0, you can use the built-in SQLite module:

auth.ts
import { entroAuth } from "@entro314labs/entro-auth";
import { DatabaseSync } from "node:sqlite";

export const auth = entroAuth({
  database: new DatabaseSync("database.sqlite"),
});

To run your application with Node.js SQLite:

node your-app.js

Bun Built-in SQLite

Warning

Use bunx with the --bun flag to run cli commands to prevent seeing type errors related to recognizing the bun:sqlite module, eg: bunx --bun @entro314labs/entro-auth-cli@latest generate

You can also use the built-in SQLite module in Bun, which is similar to the Node.js version:

auth.ts
import { entroAuth } from "@entro314labs/entro-auth";
import { Database } from "bun:sqlite";

export const auth = entroAuth({
  database: new Database("database.sqlite"),
});

Schema generation & migration

The Entro Auth CLI allows you to generate or migrate your database schema based on your Entro Auth configuration and plugins.

SQLite Schema Generation

SQLite Schema Migration

✅ Supported✅ Supported
npx @entro314labs/entro-auth-cli@latest migrate

Joins

Database joins are useful when Entro Auth needs to fetch related data from multiple tables in a single query. Endpoints like /get-session, /get-full-organization and many others benefit greatly from this feature, seeing upwards of 2x to 3x performance improvements depending on database latency.

The Kysely SQLite dialect supports joins out of the box since version 1.4.0. To enable this feature, set advanced.database.joins to true in your auth configuration.

auth.ts
import { entroAuth } from "@entro314labs/entro-auth";

export const auth = entroAuth({
  advanced: {
    database: {
      joins: true,
    },
  },
});

Additional Information

SQLite is supported under the hood via the Kysely adapter, any database supported by Kysely would also be supported. (Read more here)

If you're looking for performance improvements or tips, take a look at our guide to performance optimizations.