Database Adapters.
PostgreSQL, MySQL, and SQLite, all powered by Drizzle ORM. Pick the database that fits your project and switch adapters without changing application code.
Nextly uses a database adapter pattern that abstracts the database layer behind a common interface. All three adapters extend a shared DrizzleAdapter base class from @nextlyhq/adapter-drizzle, which provides CRUD operations, query building, and transaction management through Drizzle ORM.
Each adapter handles database-specific details: PostgreSQL uses the pg driver with connection pooling and supports JSONB, arrays, and full-text search. MySQL uses mysql2 with connection pooling and workarounds for the missing RETURNING clause. SQLite uses better-sqlite3 with synchronous operations wrapped for async compatibility, WAL mode, and RETURNING clause support (SQLite 3.35+).
You configure your database adapter in nextly.config.ts and Nextly handles the rest: schema creation, migrations, and runtime query execution all go through the adapter.
Key capabilities
- Three Databases — PostgreSQL for production with JSONB, arrays, and full-text search. MySQL for full feature sets. SQLite for development and testing.
- Drizzle ORM — All adapters extend a shared DrizzleAdapter base class. Type-safe queries, schema management, and relational access via the Drizzle instance.
- Connection Pooling — PostgreSQL and MySQL adapters include connection pooling with configurable min/max connections, idle timeouts, and connection timeouts.
- Transaction Support — Full ACID transactions with configurable isolation levels. Automatic retry for serialization failures and deadlocks.
Capabilities by database
- JSONB — PostgreSQL: yes; MySQL: JSON only; SQLite: JSON only
- Array types — PostgreSQL: yes; MySQL: no; SQLite: no
- Full-text search — PostgreSQL: yes; MySQL: FULLTEXT; SQLite: FTS5
- RETURNING clause — PostgreSQL: yes; MySQL: no; SQLite: yes (3.35+)
- Connection pooling — PostgreSQL: pg.Pool; MySQL: mysql2; SQLite: N/A (single file)
- Savepoints — PostgreSQL: yes; MySQL: disabled; SQLite: yes
- ON CONFLICT / upsert — PostgreSQL: yes; MySQL: DUPLICATE KEY; SQLite: yes
- Auto retry — PostgreSQL: serialization + deadlock; MySQL: deadlock; SQLite: no
- Best for — PostgreSQL: production; MySQL: production; SQLite: development / testing
One package per database
- PostgreSQL (
@nextlyhq/adapter-postgres, driver: pg / node-postgres) — Full features: JSONB, arrays, full-text search, RETURNING, savepoints, connection pooling. - MySQL (
@nextlyhq/adapter-mysql, driver: mysql2) — Full feature set with workarounds for missing RETURNING clause. Connection pooling and deadlock retry. - SQLite (
@nextlyhq/adapter-sqlite, driver: better-sqlite3) — File-based or in-memory. WAL mode for concurrency. RETURNING clause support (3.35+). Great for development.
Database adapter configuration
PostgreSQL
import { defineConfig } from "nextly/config";
import { createPostgresAdapter } from "@nextlyhq/adapter-postgres";
export default defineConfig({
database: {
adapter: createPostgresAdapter({
url: process.env.DATABASE_URL!,
pool: {
min: 0,
max: 5,
idleTimeoutMs: 30000,
},
}),
},
});MySQL
import { defineConfig } from "nextly/config";
import { createMySqlAdapter } from "@nextlyhq/adapter-mysql";
export default defineConfig({
database: {
adapter: createMySqlAdapter({
url: process.env.DATABASE_URL!,
pool: {
max: 10,
idleTimeoutMs: 30000,
},
}),
},
});SQLite
import { defineConfig } from "nextly/config";
import { createSqliteAdapter } from "@nextlyhq/adapter-sqlite";
export default defineConfig({
database: {
adapter: createSqliteAdapter({
url: "file:./data/app.db",
wal: true,
foreignKeys: true,
}),
},
});Start building with Nextly
Free, open source, and yours to own. No sign-up required.