CLI Reference¶
The decentdb CLI provides all database operations through subcommands.
Global Options¶
--db=<path>- Database file path (required for most commands)--help- Show help for any command
Commands¶
exec¶
Execute SQL statements.
Options: - --sql=<statement> - SQL statement to execute - --params=<type:value> - Bind parameters (repeatable) - --timing - Show execution timing - --format=<json|csv|table> - Output format (default: json) - --checkpoint - Force checkpoint after execution - --cachePages=<n> - Number of pages to cache - --cacheMb=<n> - Cache size in megabytes
Examples:
decentdb exec --db=my.ddb --sql="SELECT * FROM users"
decentdb exec --db=my.ddb --sql="INSERT INTO users VALUES (\$1, \$2)" --params=int:1 --params=text:Alice
decentdb exec --db=my.ddb --sql="SELECT * FROM users" --format=table
list-tables¶
List all tables in the database.
describe¶
Show table structure.
Options: - --table=<name> - Table name to describe
list-indexes¶
List all indexes.
Options: - --table=<name> - Filter by table (optional)
rebuild-index¶
Rebuild an index (compaction).
Options: - --index=<name> - Index name to rebuild
verify-index¶
Verify index integrity.
import¶
Import data from CSV.
Options: - --table=<name> - Target table - --file=<path> - CSV file path
export¶
Export table to CSV.
checkpoint¶
Force WAL checkpoint.
stats¶
Show database statistics.
info¶
Show detailed database information.
Output Formats¶
JSON (default)¶
CSV¶
Table¶
id | name | email
---|-------|------------------
1 | Alice | alice@example.com
2 | Bob | bob@example.com
Error Handling¶
When a command fails, the exit code is non-zero and output contains error details:
{
"ok": false,
"error": {
"code": "ERR_SQL",
"message": "Table not found",
"context": "users"
},
"rows": []
}
Environment Variables¶
DECENTDB- Path to decentdb CLI (used by test harness)PGDATABASE- PostgreSQL connection for differential tests