You're reading docs for Nextly Alpha. APIs may change between releases.

Database

Database

Choose and configure a database for your Nextly application. PostgreSQL is the recommended production database; MySQL is supported; SQLite is for local demos only.

Nextly stores data through a small set of dialect-specific adapter packages built on a shared Drizzle ORM core. Pick the adapter that matches your database, install it as a regular dependency, and Nextly handles dialect differences (placeholders, identifier escaping, RETURNING fallbacks, error classification) automatically.

Supported databases

DatabasePackageDriverUse it for
PostgreSQL@nextlyhq/adapter-postgrespgRecommended for production. Full feature set: JSONB, arrays, full-text search, ILIKE, savepoints, RETURNING.
MySQL@nextlyhq/adapter-mysqlmysql2Supported. Use it when you already run MySQL or a MySQL-compatible cloud database. Some features are emulated -- see the page.
SQLite@nextlyhq/adapter-sqlitebetter-sqlite3Local demos only. Single-writer, file-based, no SSL. Not recommended for serious local development -- run Postgres in Docker instead.

For minimum versions, cloud-provider compatibility, and the policy on MySQL-compatible variants (MariaDB, TiDB, Aurora MySQL, PlanetScale, Vitess), see database support.

Quick recommendation

Use PostgreSQL. It is the recommended production database, the only adapter with the full feature set, and the easiest to run locally with Docker (docker compose up -d postgres). Pick MySQL only if you already run it. Pick SQLite only for one-off local demos.

Installation

Each adapter is a regular npm package. Install the adapter and its peer driver in your project.

# PostgreSQL (recommended)
pnpm add @nextlyhq/adapter-postgres pg

# MySQL
pnpm add @nextlyhq/adapter-mysql mysql2

# SQLite (local demos only)
pnpm add @nextlyhq/adapter-sqlite better-sqlite3
# PostgreSQL (recommended)
npm install @nextlyhq/adapter-postgres pg

# MySQL
npm install @nextlyhq/adapter-mysql mysql2

# SQLite (local demos only)
npm install @nextlyhq/adapter-sqlite better-sqlite3
# PostgreSQL (recommended)
yarn add @nextlyhq/adapter-postgres pg

# MySQL
yarn add @nextlyhq/adapter-mysql mysql2

# SQLite (local demos only)
yarn add @nextlyhq/adapter-sqlite better-sqlite3
# PostgreSQL (recommended)
bun add @nextlyhq/adapter-postgres pg

# MySQL
bun add @nextlyhq/adapter-mysql mysql2

# SQLite (local demos only)
bun add @nextlyhq/adapter-sqlite better-sqlite3

Selecting a dialect

Nextly's runtime picks the dialect from environment variables, in this order:

  1. DB_DIALECT -- explicit override. One of postgresql, mysql, sqlite.
  2. DATABASE_URL protocol -- postgres:// / postgresql:// -> PostgreSQL, mysql:// -> MySQL, file: (or *.db / *.sqlite) -> SQLite.
  3. Fallback -- PostgreSQL with a warning. Always set DB_DIALECT explicitly to avoid the warning.

Minimal .env files for each dialect:

.env (PostgreSQL)
DB_DIALECT=postgresql
DATABASE_URL=postgres://nextly:nextly@localhost:5432/nextly_dev
.env (MySQL)
DB_DIALECT=mysql
DATABASE_URL=mysql://nextly:nextly@localhost:3306/nextly_dev
.env (SQLite, local demo only)
DB_DIALECT=sqlite
DATABASE_URL=file:./data/nextly.db

Feature comparison

The adapters share a single CRUD API, but underlying dialect capabilities differ. The shared DrizzleAdapter base reports per-dialect capabilities at runtime; this table is a quick reference.

FeaturePostgreSQLMySQLSQLite
JSONB columnsYesNo (JSON only)No (JSON as TEXT)
Array columnsYesNoNo
RETURNING clauseYesNo (extra SELECT after writes)Yes (3.35+)
ILIKE (case-insensitive)NativeLOWER(...) LIKE LOWER(...) fallbackLOWER(...) LIKE LOWER(...) fallback
Savepoints (nested transactions)YesDisabled by adapterYes
Full-text searchtsvectorFULLTEXT indexesFTS5 (extension)
Upsert syntaxON CONFLICT DO UPDATEON DUPLICATE KEY UPDATEON CONFLICT DO UPDATE
Connection poolingpg.Poolmysql2 poolNone (single file handle)
Generated columnsYesYesYes
Max query parameters65,53565,535999
SSL / TLSYesYesN/A (local file)
Deadlock retryOn 40001 / 40P01 (configurable)On error 1213 (configurable)N/A
Auto-detected providersNeon, Supabase, standardNoneNone

Next steps