CosmoSQLClient.CosmoKv.Cli 7.46.0

dotnet tool install --global CosmoSQLClient.CosmoKv.Cli --version 7.46.0
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local CosmoSQLClient.CosmoKv.Cli --version 7.46.0
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=CosmoSQLClient.CosmoKv.Cli&version=7.46.0
                    
nuke :add-package CosmoSQLClient.CosmoKv.Cli --version 7.46.0
                    

cosmokv-sql — CLI shell for CosmoKv databases

Interactive command-line shell for CosmoKv embedded databases, in the spirit of sqlite3. REPL, one-shot SQL, stdin scripts, and four output formats. Ships as a dotnet global tool.

Install

dotnet tool install -g CosmoSQLClient.CosmoKv.Cli

After install, the binary is on PATH as cosmokv-sql.

Usage

cosmokv-sql                                    # REPL on a transient DB
cosmokv-sql [--format=FMT] <database>          # REPL on <database>
cosmokv-sql [--format=FMT] <database> [sql]    # one-shot SQL
cosmokv-sql [--format=FMT] <database> -        # read SQL from stdin
cosmokv-sql --help

<database> is either a bare directory path (e.g. ./mydb — sqlite3-style) or a full connection string (DataSource=./mydb;CreateIfMissing=false). The bare form is shorthand for DataSource=<path>;CreateIfMissing=true — the directory is auto-created if missing. Use the connection-string form when you want to require the database to already exist (set CreateIfMissing=false).

With no <database>, the REPL opens against a transient temp directory and removes it on exit — handy for trying things out. Use .open FILENAME from inside the REPL to switch to a persistent database (and keep your subsequent work).

REPL

Run with just a database path to drop into the interactive shell. Statements end with ; and may span multiple lines.

$ cosmokv-sql ./mydb
cosmokv-sql 1.5.0
Connected to './mydb'.
Enter ".help" for usage hints.
cosmokv-sql> CREATE TABLE Users (
        ...> Id BIGINT IDENTITY PRIMARY KEY,
        ...> Email NVARCHAR(256) NOT NULL);
0 rows affected.
cosmokv-sql> INSERT INTO Users (Email) VALUES ('a@b'), ('c@d');
2 rows affected.
cosmokv-sql> SELECT * FROM Users;
Id  Email
--  -----
1   a@b  
2   c@d  
(2 rows)
cosmokv-sql> .quit

One-shot

Pass SQL as the last positional argument. Useful for shell scripting and ad-hoc queries.

cosmokv-sql ./mydb "SELECT COUNT(*) AS n FROM Users"

Stdin

Pass - instead of inline SQL to pipe a script in. The CLI splits on semicolons (outside string literals) and runs each statement in order.

cat schema.sql | cosmokv-sql ./mydb -

Output formats

--format=FMT (or .format FMT inside the REPL) selects how rows are rendered. Pipe to other tools for processing.

cosmokv-sql --format=json ./mydb "SELECT Id, Email FROM Users" | jq '.[].Email'
cosmokv-sql --format=csv  ./mydb "SELECT * FROM Users" > users.csv
cosmokv-sql --format=tsv  ./mydb "SELECT * FROM Users" | column -t -s $'\t'
Format Notes
table (default) Aligned columns with a header rule.
csv RFC 4180-ish: values containing the delimiter or quotes get quoted.
tsv Tab-separated; tab/newline characters in values are flattened to spaces.
json Single array of objects per result set. Booleans and numerics are native JSON values.

REPL dot-commands

Dot-commands work only at the start of a fresh line (not mid-statement) and consume the whole line.

Command Behaviour
.help List dot-commands.
.open FILENAME Close the current connection and reopen on FILENAME (auto-created). Promotes a transient session to persistent.
.databases Show the current data source (transient: … or main: …).
.tables Names of every user table, alphabetically.
.schema [TABLE] CREATE TABLE script for TABLE (or every table if omitted). Round-trips through the parser, so you can replay it.
.indexes [TABLE] CREATE INDEX scripts for TABLE (or every table).
.dump Schema + INSERT statements for the entire database — like sqlite3's .dump. Safe to replay against an empty CosmoKv.
.backup FILENAME Write a COSMOBAK snapshot to FILENAME. MVCC — writes continue uninterrupted. Refuses to overwrite an existing file.
.vacuum Run value-log GC to reclaim space from tombstoned/overwritten large values. Prints the number of vlog files dropped.
.format FMT Switch the output format mid-session.
.quit / .exit / Ctrl-D Leave the shell.

Examples

Snapshot a database to a script:

cosmokv-sql ./prod-db ".dump" > snapshot.sql
cosmokv-sql ./fresh-db - < snapshot.sql

Pipe a query result into another tool:

cosmokv-sql --format=json ./mydb "SELECT * FROM Events WHERE created_at > '2026-05-01'" \
  | jq 'group_by(.user_id) | map({user_id: .[0].user_id, n: length})'

Run a migration script:

cosmokv-sql ./mydb - < migrations/001_schema.sql

Limitations

  • Statement splitting is lexical only — it understands single-quoted strings but not block comments or T-SQL GO. A trailing ; ends the current statement.
  • No readline-style history or autocomplete; if you want those, wrap the CLI with rlwrap.
  • .dump rewrites every row as a fully-qualified INSERT. For tables with millions of rows, prefer .backup FILENAME — it writes a COSMOBAK snapshot directly without the parse/encode round-trip.
  • .backup only writes plaintext snapshots. To re-encrypt with a different key, use BackupAsync(stream, backupKey) in code.
  • Opening an encrypted store from the shell requires a connection string with EncryptionKey=<base64> (32-byte AES-256 key, base64-encoded). Bare-path .open ./mydb opens unencrypted.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
7.46.0 343 2026/8/26
7.45.1 125 2026/8/26
7.45.0 125 2026/8/25
7.44.0 178 2026/8/5
7.43.0 137 2026/8/5
7.42.0 135 2026/8/5
7.41.0 136 2026/8/5
7.40.0 133 2026/8/5
7.39.0 128 2026/8/4
7.38.0 142 2026/8/4
7.37.0 128 2026/8/4
7.36.0 144 2026/8/4
7.35.1 129 2026/8/4
7.34.3 134 2026/8/4
7.34.2 131 2026/8/4
7.33.0 139 2026/8/3
7.32.0 146 2026/8/3
7.31.0 150 2026/7/31
7.30.0 135 2026/7/30
7.29.0 135 2026/7/30
Loading failed