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 ./publishThe 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
csharpdbRemote 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| Flag | Aliases | Description |
|---|---|---|
--endpoint <uri> | --server | Remote 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://orhttps://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.jsonInteractive 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> .quitMulti-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:
| Type | Colour | Example |
|---|---|---|
INTEGER / REAL | Yellow | 42, 3.14 |
TEXT | Green | Alice |
BLOB | Magenta | BLOB(128 bytes) |
NULL | Dim italic | NULL |
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
| Command | Description |
|---|---|
.info | Show 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. |
.views | List 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 |
.collections | List document collections (NoSQL API) |
Transaction Management
| Command | Description |
|---|---|
.begin | Begin an explicit transaction. Disables snapshot mode. |
.commit | Commit the current transaction |
.rollback | Rollback the current transaction |
Database Maintenance
| Command | Description |
|---|---|
.checkpoint | Flush 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. |
.vacuum | Rewrite 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
| Command | Description |
|---|---|
.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
| Command | Description |
|---|---|
.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
| Command | Description |
|---|---|
.help | Show a list of all available commands |
.quit / .exit | Exit 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-onlyApply from the REPL:
csdb> .migrate-fks fk-spec.json --backup pre-fk.backup.dbNotes:
--validate-onlyreports sampled violations without mutating the database.--backupwrites 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 Code | Meaning |
|---|---|
0 | No warnings or errors |
1 | Warnings present, no errors |
2 | Errors present |
64 | Invalid CLI usage |
| Command | Description |
|---|---|
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.
| Command | Description |
|---|---|
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.dbETL 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.jsonPipeline Catalog
| Command | Description |
|---|---|
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
| Command | Description |
|---|---|
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 offTransactions
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) returnedFile 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 grpcMaintenance
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.jsonETL 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