CSharpDB CLI Reference

The CSharpDB CLI (CSharpDB.Cli) is an interactive REPL for working with CSharpDB databases from the terminal. It supports SQL execution, meta-commands for introspection, transaction management, batch file execution, storage diagnostics, maintenance operations, and ETL pipeline management.

Installation

Build the CLI from source to produce the csharpdb executable. Requires .NET 10 SDK.

# Build framework-dependent (requires .NET 10 runtime on target)
dotnet publish src/CSharpDB.Cli -c Release -o ./publish

# Build self-contained (no runtime required on target)
dotnet publish src/CSharpDB.Cli -c Release -r win-x64 --self-contained -o ./publish

# Build self-contained for Linux
dotnet publish src/CSharpDB.Cli -c Release -r linux-x64 --self-contained -o ./publish

The output directory will contain the csharpdb executable (or csharpdb.exe on Windows). Add it to your PATH for global access. See the Downloads page for all platform targets.

Running the CLI

Interactive REPL (default)

# Open or create a database
csharpdb mydata.db

# Without arguments, uses csharpdb.db in the current directory
csharpdb

Remote Connectivity

Connect to a remote CSharpDB server instead of a local file:

# Connect via HTTP (REST API)
csharpdb -- --endpoint http://localhost:61818

# Connect via gRPC (Daemon)
csharpdb -- --endpoint https://localhost:49995 --transport grpc

# Connect via Named Pipes
csharpdb -- --endpoint mypipe --transport namedpipes
FlagAliasesDescription
--endpoint <uri>--serverRemote server URI
--transport <type>Connection transport: direct (default), http, grpc, namedpipes (aliases: named-pipes, pipe, npipe)

Constraints:

  • Cannot specify both a positional database path and --endpoint.
  • Non-direct transports (http, grpc, namedpipes) require --endpoint.
  • If an http:// or https:// endpoint is given without --transport, HTTP is inferred.

Command Mode

If the first argument is a recognised command name, the CLI runs that command and exits instead of entering the REPL:

csharpdb -- inspect mydata.db
csharpdb -- inspect-page mydata.db 5 --hex
csharpdb -- check-wal mydata.db
csharpdb -- check-indexes mydata.db --json
csharpdb -- maintenance-report mydata.db
csharpdb -- reindex mydata.db --all
csharpdb -- vacuum mydata.db
csharpdb -- migrate-foreign-keys mydata.db --spec fk-spec.json --validate-only
csharpdb -- etl run mydata.db pipeline.json

Interactive Usage

The REPL displays a csdb> prompt. Enter SQL statements followed by a semicolon, or use dot-prefixed meta-commands:

csdb> CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL, age INTEGER);
OK (0 ms)

csdb> INSERT INTO users VALUES (1, 'Alice', 30);
1 row(s) affected (1 ms)

csdb> SELECT * FROM users;
┌────┬───────┬─────┐
│ id │ name  │ age │
├────┼───────┼─────┤
│  1 │ Alice │  30 │
└────┴───────┴─────┘
1 row(s) returned (0 ms)

csdb> .quit

Multi-line SQL is supported — the REPL waits for a semicolon before executing. The continuation prompt changes to ...>. Trigger bodies (BEGIN ... END;) are handled correctly as single statements.

Output Formatting

Query results are rendered as Unicode box-drawing tables with ANSI colour coding:

TypeColourExample
INTEGER / REALYellow42, 3.14
TEXTGreenAlice
BLOBMagentaBLOB(128 bytes)
NULLDim italicNULL

Column widths are capped at 40 characters; longer values are truncated with . Numeric columns are right-aligned; text columns are left-aligned.

Meta-Commands

All meta-commands start with a dot (.). They are case-insensitive.

Database Introspection

CommandDescription
.infoShow database status: table, index, view, trigger, and collection counts, plus current modes
.tables [PATTERN|--all]List tables. By default, collection backing tables are hidden. Use a pattern to filter or --all to include internal tables.
.schema [TABLE|--all]Show the CREATE TABLE schema for one or all tables. Includes columns, types, constraints, IDENTITY, and foreign key definitions.
.indexes [TABLE]List indexes, optionally filtered by table name. Shows name, table, columns, and UNIQUE flag.
.viewsList all views
.view <NAME>Show the CREATE VIEW SQL for a specific view
.triggers [TABLE]List triggers, optionally filtered by table name. Shows name, timing, event, and target table.
.trigger <NAME>Show the CREATE TRIGGER SQL for a specific trigger
.collectionsList document collections (NoSQL API)

Transaction Management

CommandDescription
.beginBegin an explicit transaction. Disables snapshot mode.
.commitCommit the current transaction
.rollbackRollback the current transaction

Database Maintenance

CommandDescription
.checkpointFlush WAL pages to the main database file
.backup <FILE> [--with-manifest]Write a committed snapshot backup to a file, optionally with a JSON manifest (SHA-256, byte count, page count, change counter)
.restore <FILE> [--validate-only]Validate a source snapshot or restore it into the current database file; for remote transports the path is resolved on the target host
.reindex [--all|--table <name>|--index <name>] [--force-corrupt-rebuild]Rebuild indexes. --all (default) rebuilds all indexes. --force-corrupt-rebuild recovers corrupt index trees.
.vacuumRewrite the database file to reclaim free pages. Shows before/after byte and page counts.
.migrate-fks <SPEC.json> [--validate-only] [--backup <FILE>]Validate or apply foreign-key retrofit migration for existing tables; for remote transports, paths resolve on the connected host

Mode Toggles

CommandDescription
.timing [on|off|status]Toggle query timing output (shows execution time in milliseconds). Defaults to on.
.snapshot [on|off|status]Toggle snapshot (read-only) mode for SELECT queries. When enabled, queries use a frozen point-in-time view that is unaffected by concurrent writes. Local direct access only.
.syncpoint [on|off|status]Toggle the sync fast path for primary key lookups. When enabled, cached PK lookups bypass the async pipeline for lower latency. Local direct access only.

File Execution

CommandDescription
.read <FILE>Execute all SQL statements from a file. Statements are separated by semicolons. Results and errors are printed as they execute. Reports pass/fail counts.

General

CommandDescription
.helpShow a list of all available commands
.quit / .exitExit the REPL

Foreign-Key Retrofit Migration

Use the retrofit workflow when an older database file already contains valid parent/child data but does not yet persist FK metadata:

{
  "validateOnly": true,
  "violationSampleLimit": 100,
  "constraints": [
    {
      "tableName": "orders",
      "columnName": "customer_id",
      "referencedTableName": "customers",
      "referencedColumnName": "id",
      "onDelete": "Restrict"
    }
  ]
}

Validate only:

csharpdb -- migrate-foreign-keys mydata.db --spec fk-spec.json --validate-only

Apply from the REPL:

csdb> .migrate-fks fk-spec.json --backup pre-fk.backup.db

Notes:

  • --validate-only reports sampled violations without mutating the database.
  • --backup writes a committed snapshot before apply mode starts.
  • For HTTP or gRPC transports, the spec path and backup path are resolved on the connected host.

SQL Introspection (sys.*)

You can query metadata with SQL in addition to dot-commands:

SELECT * FROM sys.tables ORDER BY table_name;
SELECT * FROM sys.columns WHERE table_name = 'users' ORDER BY ordinal_position;
SELECT * FROM sys.indexes WHERE table_name = 'users';
SELECT * FROM sys.foreign_keys ORDER BY table_name, column_name;
SELECT * FROM sys.views;
SELECT * FROM sys.triggers;
SELECT * FROM sys.objects ORDER BY object_type, object_name;
SELECT * FROM sys.saved_queries ORDER BY name;

Underscored aliases are supported: sys_tables, sys_columns, sys_indexes, sys_foreign_keys, sys_views, sys_triggers, sys_objects, sys_saved_queries.

sys.columns includes is_identity (0/1) in addition to is_primary_key.

Storage Inspector Commands

These read-only commands diagnose database files and return deterministic exit codes for automation:

Exit CodeMeaning
0No warnings or errors
1Warnings present, no errors
2Errors present
64Invalid CLI usage
CommandDescription
inspect <dbfile> [--json] [--out <file>] [--include-pages]Full DB file/header/page integrity scan
inspect-page <dbfile> <pageId> [--json] [--hex]Inspect one page and optionally include hex dump
check-wal <dbfile> [--json]Validate WAL header/frames/salts/checksums
check-indexes <dbfile> [--index <name>] [--sample <n>] [--json]Validate index catalog/root/table/column consistency

See Storage Inspector for full rule IDs and JSON contract details.

Maintenance Commands

Standalone maintenance operations that run outside the REPL. All support --json for machine-readable output and use the same exit codes as inspector commands.

CommandDescription
maintenance-report <dbfile> [--json]Show space usage, fragmentation metrics, and page distribution
reindex <dbfile> [--all|--table <name>|--index <name>] [--force-corrupt-rebuild] [--json]Rebuild indexes. --force-corrupt-rebuild recovers corrupt index trees.
vacuum <dbfile> [--json]Rewrite database file to reclaim free pages. Reports before/after byte and page counts.
migrate-foreign-keys <dbfile> --spec <json-file> [--validate-only] [--backup <file>] [--json]Validate or apply foreign-key retrofit migration
# Generate a maintenance report
csharpdb -- maintenance-report mydata.db

# Rebuild all indexes
csharpdb -- reindex mydata.db --all

# Rebuild indexes for a specific table
csharpdb -- reindex mydata.db --table users

# Recover a corrupt index
csharpdb -- reindex mydata.db --index idx_users_name --force-corrupt-rebuild

# Compact the database file
csharpdb -- vacuum mydata.db

ETL Pipeline Commands

Manage and execute ETL pipelines from the command line. All pipeline commands are prefixed with etl.

Pipeline Execution

# Validate a pipeline package without executing
csharpdb -- etl validate mydata.db pipeline.json

# Simulate execution without writing to the destination
csharpdb -- etl dry-run mydata.db pipeline.json

# Execute the full pipeline and commit results
csharpdb -- etl run mydata.db pipeline.json

Pipeline Catalog

CommandDescription
etl list <dbfile> [--json]List all pipeline runs with status, mode, and name
etl pipelines <dbfile> [--json]List all stored pipelines with version and revision info
etl revisions <dbfile> <name> [--json]List all revisions of a specific pipeline
etl import <dbfile> <packagefile> [--name <name>] [--json]Import a pipeline package into the database. --name overrides the pipeline name.
etl export <dbfile> <name> <packagefile>Export a stored pipeline to a package file
etl export-revision <dbfile> <name> <revision> <packagefile>Export a specific pipeline revision to a package file
etl delete <dbfile> <name>Delete a stored pipeline

Pipeline Run Management

CommandDescription
etl status <dbfile> <runId> [--json]Get status of a specific pipeline run
etl run-package <dbfile> <runId> [--json]Get the package definition used for a run
etl rejects <dbfile> <runId> [--json]Get rejected rows from a pipeline run
etl resume <dbfile> <runId> [--json]Resume a failed or incomplete pipeline run

Examples

Introspection

csdb> .tables
  users
  orders
  products

csdb> .schema users
CREATE TABLE users (
  id INTEGER PRIMARY KEY IDENTITY,
  name TEXT NOT NULL,
  age INTEGER
)

csdb> .indexes users
  idx_users_name  ON users(name)  UNIQUE

csdb> .info
  Tables:      3
  Indexes:     2
  Views:       1
  Triggers:    1
  Collections: 0
  Mode: WAL enabled, timing off, snapshot off

Transactions

csdb> .begin
Transaction started.

csdb> INSERT INTO users VALUES (10, 'Test', 99);
1 row(s) affected

csdb> .rollback
Transaction rolled back.

csdb> SELECT * FROM users WHERE id = 10;
0 row(s) returned

File Execution

csdb> .read samples/ecommerce-store/schema.sql
Executing 84 statements...
84 succeeded, 0 failed.

Snapshot Mode

csdb> .snapshot on
Snapshot mode enabled.

csdb> SELECT COUNT(*) FROM users;
┌──────────┐
│ COUNT(*) │
├──────────┤
│       42 │
└──────────┘

csdb> .snapshot off
Snapshot mode disabled.

Remote Connectivity

# Connect to the REST API
csharpdb -- --endpoint http://localhost:61818

# Connect to the gRPC daemon
csharpdb -- --endpoint https://localhost:49995 --transport grpc

Maintenance

csdb> .vacuum
Vacuum complete. Before: 40960 bytes (10 pages) → After: 32768 bytes (8 pages)

csdb> .reindex --table users
Rebuilt 2 index(es).

csdb> .backup mydata.backup.db --with-manifest
Backup written to mydata.backup.db
Manifest written to mydata.backup.db.manifest.json

ETL Pipelines

# Import and run a pipeline
csharpdb -- etl import mydata.db pipeline.json
csharpdb -- etl run mydata.db pipeline.json

# Check run history
csharpdb -- etl list mydata.db

See Also