CLI
Durcno ships a command-line interface for project scaffolding, database interaction, and migration management.
- npm
- pnpm
- Bun
- Yarn
npm exec durcno <command> [options]
pnpm exec durcno <command> [options]
bunx durcno <command> [options]
yarn durcno <command> [options]
Commands
| Command | Description |
|---|---|
init | Initialize a new Durcno project |
repl | Open an interactive SQL REPL |
exec | Execute SQL non-interactively |
generate | Generate a new migration from schema changes |
migrate | Apply pending migrations |
push | Generate and apply a migration in one step |
down <migration> | Rollback a specific migration |
squash <start> <end> | Squash a range of migrations into one |
status | Show migration status |
Migration commands (generate, migrate, push, down, squash, status) are covered in the Migrations section.
init
Initialize a new Durcno project with an interactive setup wizard.
- npm
- pnpm
- Bun
- Yarn
npm exec durcno init [--force]
pnpm exec durcno init [--force]
bunx durcno init [--force]
yarn durcno init [--force]
Options
--force— Overwrite existing files without prompting.
What it does
The init command walks you through an interactive prompt to configure your project:
- Select a database connector — Choose from:
pg(node-postgres)postgres(postgres.js)bun(Bun SQL)pglite(WASM)
- Enter a connection URL — Your PostgreSQL connection string, or leave empty to use
process.env.DATABASE_URL! - Schema file path — Where to create your schema file (default:
db/schema.ts) - Migrations directory — Where to store migration files (default:
migrations)
Generated files
After completion, the following files are created:
durcno.config.ts— Database configuration filedb/schema.ts— Starter schema with an exampleUserstabledb/index.ts— Database query API
Example
- npm
- pnpm
- Bun
- Yarn
npm exec durcno init
pnpm exec durcno init
bunx durcno init
yarn durcno init
🚀 Durcno Project Setup
? Select a database connector: pg (node-postgres)
? Connection URL (leave empty to use process.env.DATABASE_URL!):
? Schema file: db/schema.ts
? Migrations directory: migrations
📄 Creating files ...
✔ Created durcno.config.ts
✔ Created db/schema.ts
✔ Created db/index.ts
✨ Project initialized successfully!
After initialization, follow the next steps printed in the terminal to generate and apply your first migration.
In non-interactive environments (CI, piped input), init uses default values automatically.
repl
Open an interactive SQL REPL connected to your database.
- npm
- pnpm
- Bun
- Yarn
npm exec durcno repl [--config path/to/durcno.config.ts]
pnpm exec durcno repl [--config path/to/durcno.config.ts]
bunx durcno repl [--config path/to/durcno.config.ts]
yarn durcno repl [--config path/to/durcno.config.ts]
Options
--config <path>— Path to the config file (defaults todurcno.config.ts).
Features
- Execute any SQL query directly against your database
- Multi-line input — queries are executed when they end with
; - Query results displayed in a formatted table
- Execution time reported for each query
- Command history (up to 100 entries)
Meta commands
The REPL supports psql-style meta commands:
| Command | Description |
|---|---|
\dt, \d | List all tables |
\dn | List all schemas |
\du | List all roles |
\clear | Clear the screen |
\?, \help | Show available meta commands |
Example
- npm
- pnpm
- Bun
- Yarn
npm exec durcno repl
pnpm exec durcno repl
bunx durcno repl
yarn durcno repl
✔ Connected to database
DURCNO REPL
Type SQL queries and press Enter to execute.
Enter "exit" or "quit" to close the REPL.
durcno> SELECT * FROM "public"."users";
id | name | email
---+----------+-----------------
1 | John Doe | john@example.com
(1 row) (12.34ms)
durcno> \dt
Tables:
• public.users
durcno> exit
✔ Connection closed.
Press Ctrl+C during multi-line input to cancel the current query. Press Ctrl+C at the prompt to close the REPL.
exec
Execute SQL without opening a REPL, using the connector and credentials from durcno.config.ts. Intended for scripts, CI, and AI agents.
- npm
- pnpm
- Bun
- Yarn
npm exec durcno exec --command 'select * from "public"."users"' --json
pnpm exec durcno exec --command 'select * from "public"."users"' --json
bunx durcno exec --command 'select * from "public"."users"' --json
yarn durcno exec --command 'select * from "public"."users"' --json
Options
-c, --command <sql>— SQL to execute.-f, --file <path>— Read SQL from a file.--json— Print returned rows as a single JSON array.-q, --quiet— Suppress timings and row counts.--config <path>— Path to the config file (defaults todurcno.config.ts).
--command and --file cannot be combined. When neither is provided, SQL is read from piped stdin; exec never opens a REPL.
Behavior
- Statements run sequentially and execution stops at the first error.
- The command exits
0on success and1on failure. - Query data is written to stdout; errors are written to stderr.
--jsonprints one valid JSON array for the whole run ([]for DDL-only input), with 64-bit integers serialized as strings.- Meta commands are supported when they make up the entire input, for example
durcno exec -c '\dt'.
Examples
- npm
- pnpm
- Bun
- Yarn
# One-shot query
npm exec durcno exec -c 'select * from "public"."users" limit 5'
# Machine-readable output
npm exec durcno exec -c 'select * from "public"."users" limit 5' --json
# Run a file
npm exec durcno exec -f db/seed.sql
# Pipe a script
cat db/seed.sql | npm exec durcno exec --json
# One-shot query
pnpm exec durcno exec -c 'select * from "public"."users" limit 5'
# Machine-readable output
pnpm exec durcno exec -c 'select * from "public"."users" limit 5' --json
# Run a file
pnpm exec durcno exec -f db/seed.sql
# Pipe a script
cat db/seed.sql | pnpm exec durcno exec --json
# One-shot query
bunx durcno exec -c 'select * from "public"."users" limit 5'
# Machine-readable output
bunx durcno exec -c 'select * from "public"."users" limit 5' --json
# Run a file
bunx durcno exec -f db/seed.sql
# Pipe a script
cat db/seed.sql | bunx durcno exec --json
# One-shot query
yarn durcno exec -c 'select * from "public"."users" limit 5'
# Machine-readable output
yarn durcno exec -c 'select * from "public"."users" limit 5' --json
# Run a file
yarn durcno exec -f db/seed.sql
# Pipe a script
cat db/seed.sql | yarn durcno exec --json