SQLite
Set up Nextly with SQLite, which is great on your own machine and on a single server; on Vercel, choose PostgreSQL. This page covers when (and when not) to use it, install instructions, file paths, WAL mode, and limitations.
SQLite is great on your own machine and on a single server; on Vercel, choose PostgreSQL. The database is one file beside your app, so it needs no server and starts with the project. Writes take turns on that file, which suits one app on one machine. On Vercel and other serverless hosts each function has its own short-lived disk, so a file written there neither lasts nor reaches the others: use PostgreSQL there, and wherever several servers share one database. See the PostgreSQL setup page.
The SQLite adapter wraps better-sqlite3 -- a synchronous C++ binding -- behind the same async DrizzleAdapter interface as the other dialects. It needs no infrastructure: npx create-nextly-app@alpha uses it by default, and a test suite can run it in memory.
Minimum version: SQLite 3.38. The pinned
better-sqlite3ships a much newer SQLite (3.45+ at time of writing), so users on this package always pass the version check. See database support.
Installation
Install the adapter alongside the better-sqlite3 driver:
pnpm add @nextlyhq/adapter-sqlite better-sqlite3npm install @nextlyhq/adapter-sqlite better-sqlite3yarn add @nextlyhq/adapter-sqlite better-sqlite3bun add @nextlyhq/adapter-sqlite better-sqlite3better-sqlite3 is a native module that compiles on npm install. Make sure your platform has a working C++ toolchain (build-essential on Linux, Xcode CLT on macOS, Visual Studio Build Tools on Windows).
Configuration
Set DB_DIALECT=sqlite and DATABASE_URL with a file: prefix. The CLI commands that use the database (nextly migrate, nextly db:sync and the other migrate:* commands) refuse to run without DATABASE_URL, on SQLite too.
DB_DIALECT=sqlite
DATABASE_URL=file:./data/nextly.dbIf DATABASE_URL is unset, the running app falls back to file:./data/nextly.db and logs a warning in development, but those CLI commands do not, so set it. The adapter creates the file automatically if it does not exist.
Programmatic usage
import { createSqliteAdapter } from "@nextlyhq/adapter-sqlite";
const adapter = createSqliteAdapter({
url: "file:./data/nextly.db",
});
await adapter.connect();File path
The url option accepts a path with an optional file: prefix. The adapter strips the prefix before opening:
createSqliteAdapter({ url: "file:./data/nextly.db" }); // relative to CWD
createSqliteAdapter({ url: "/absolute/path/nextly.db" }); // absolute
createSqliteAdapter({ url: "file:./data/nextly.db" }); // with prefixIf memory: true is set, the adapter ignores url and opens an in-memory database (:memory:).
In-memory databases
For tests or ephemeral demos:
const adapter = createSqliteAdapter({ memory: true });In-memory databases are extremely fast but disappear when the process exits. Each adapter instance gets its own database -- they are not shared between processes or workers.
SQLite-specific options
| Option | Type | Default | Description |
|---|---|---|---|
wal | boolean | true | Enable WAL (Write-Ahead Logging) mode for better concurrent-read performance. Auto-disabled for in-memory and read-only databases. |
busyTimeout | number (ms) | 5000 | How long to wait when another process holds the database file, or a Schema Builder save holds the entry's collection, before the write fails as DATABASE_BUSY (for the file, the driver's SQLITE_BUSY). |
pool.connectionTimeoutMs | number (ms) | 15000 | How long a transaction waits for the database connection behind the transactions ahead of it, before it fails as DATABASE_BUSY. 0 waits without limit. |
foreignKeys | boolean | true | Enable PRAGMA foreign_keys = ON. SQLite ships with this off by default; the adapter turns it on. |
memory | boolean | false | Open an in-memory database. Overrides url. |
readonly | boolean | false | Open in read-only mode. Disables WAL because changing journal mode requires write access. |
queryTimeoutMs | number (ms) | 15000 | Default for the adapter's internal timeout helpers. |
const adapter = createSqliteAdapter({
url: "file:./data/nextly.db",
wal: true,
foreignKeys: true,
busyTimeout: 5000,
});A request can wait in two places on SQLite, and each has its own setting. The adapter has one connection, so a transaction waits for the ones ahead of it to finish, for at most pool.connectionTimeoutMs, the same setting that bounds the wait for a pooled connection on PostgreSQL and MySQL. A write also waits while another process holds the database file, or while a Schema Builder save that deletes a field's values holds its collection, for at most busyTimeout. Either wait running out answers the request as DATABASE_BUSY (503, Retry-After: 5), and the transaction or write that waited does not run. A write in a transaction already open does not wait for such a save, which needs the connection the transaction has: it is refused at once, as DATABASE_BUSY too.
WAL mode
WAL is enabled by default for file-based databases. It allows multiple concurrent readers while a writer is active, significantly reducing read-side contention. WAL is automatically skipped when:
- The database is in-memory (
:memory:does not need WAL). - The database is opened read-only (changing the journal mode requires write access).
WAL mode creates two sidecar files alongside the database: <name>.db-wal and <name>.db-shm. Don't delete them while the app is running.
Environment variables
Set the database path in DATABASE_URL, with a file: prefix:
DB_DIALECT=sqlite
DATABASE_URL=file:./data/nextly.dbSQLITE_PATH is accepted by the environment check but is not used to open the database: use DATABASE_URL.
Limitations
SQLite is intentionally simple, and that simplicity is the trade-off:
- Single writer. Only one write operation at a time -- writes are globally serialized regardless of WAL mode. Concurrent writes from different processes wait on the busy timeout, then fail, so one app on one server is the shape it suits.
- No connection pooling. A single file handle.
getPoolStats()returnsnull. There is no path to scale write throughput across connections. - No SSL / TLS. SQLite is a local file; remote access does not exist. If your app is in another container, the file is not.
- Local disk only. SQLite's locking relies on the file sitting on a local disk; running it over NFS, SMB or some Docker bind mounts can corrupt the database.
- Weaker schema operations. SQLite's
ALTER TABLEis much more limited than PostgreSQL or MySQL -- some column changes require recreating the table. Nextly's migration model handles this where possible, but you will hit cases the other dialects handle natively. - Weaker types. SQLite uses dynamic typing with type affinity; numbers, strings, and dates flow through with less validation than PostgreSQL or MySQL provide.
- No
ILIKE. Case-insensitive search folds both sides, then compares withLIKE. SQLite's ownLOWER()folds ASCII letters only, so Nextly registers a Unicode case fold,nextly_fold_case(), on every connection it opens and folds with that: "CRÈME" finds "crème" as on PostgreSQL and MySQL. A connection opened by other software does not have the function, and a Nextly search run on one fails withno such function: nextly_fold_caserather than matching ASCII letters only. - No JSONB. JSON is stored as TEXT and queried with
json_extract(). No JSON indexes. - No array types. Store arrays as JSON text.
- 999 parameter limit per query. PostgreSQL and MySQL allow 65,535. Bulk operations may need batching at lower thresholds for SQLite.
- No native full-text search by default. FTS5 ships with
better-sqlite3but is not wired through Nextly's query builder.
Implementation notes
- The adapter wraps
better-sqlite3's synchronous API inPromise.resolve(...)to match the asyncDrizzleAdaptercontract. RETURNINGis supported (SQLite 3.35+) and used automatically forINSERT/UPDATE/DELETE.- Placeholders: the base adapter emits
$1,$2-- the SQLite adapter rewrites them to?before execution. - Transactions use
BEGIN IMMEDIATEto acquire a write lock at the start, which avoids the upgrade-deadlock pattern where two readers try to become writers concurrently. - Savepoints are fully supported for nested transactions.
- JavaScript values are sanitized before binding:
boolean -> 0/1,Date -> ISO string, plain objects ->JSON.stringify(...),undefined -> null.
Migrations
The migration CLI works the same as for the other dialects:
pnpm nextly migrate:create --name=add-posts-table
pnpm nextly migrate:status
pnpm nextly migrate:check
pnpm nextly migrate
pnpm nextly migrate:fresh # destructiveRolling back.
nextly migrate:downrolls back the most recently applied migration using its-- DOWNsection; there is nomigrate:rollback. For anything else, write a new corrective migration. See production migrations.
Capabilities
The adapter reports the following capabilities at runtime:
{
dialect: "sqlite",
supportsJsonb: false,
supportsJson: true,
supportsArrays: false,
supportsGeneratedColumns: true,
supportsFts: true,
supportsIlike: false,
supportsReturning: true,
supportsSavepoints: true,
supportsOnConflict: true,
maxParamsPerQuery: 999,
maxIdentifierLength: 128,
}Next steps
- PostgreSQL setup -- for Vercel, several servers, or the full feature set
- Database overview -- feature comparison across dialects
- Database support -- minimum versions
- Production migrations -- forward-only deploy patterns
MySQL
Set up Nextly with MySQL. Covers installation, connection strings, charset and collation, pool tuning, SSL, deadlock retry, migrations, and gaps versus PostgreSQL.
Database support and version requirements
Minimum supported database versions, cloud-provider compatibility, and the warn-and-proceed policy for MySQL-compatible variants.