Reference

Command-line tool

The xod tool inspects a database, runs SQL queries, converts between formats, and adds or removes its password, without writing any code.

Getting it

The tool isn’t on NuGet yet. Run it from a clone of the repository:

git clone https://github.com/mhsallam/xod.git
cd xod
dotnet run --project src/Xod.Cli -- stats path/to/app.xod

Everything after -- goes to the tool. In the commands below, xod stands for dotnet run --project src/Xod.Cli --.

Every command opens the database exclusively, just like XodContext, so it exits with 1 and a DatabaseLockedException message while an application has the database open (see Processes).

Passing a password

Commands that take a password support three options:

  • --password "value" — direct argument (convenient locally, visible in shell history and process lists).
  • --password-env NAME — reads the password from an environment variable.
  • --password-stdin — reads the password from standard input.

On a shared machine or in scripts, prefer --password-env or --password-stdin.

Commands

stats

Prints the tables, pages, row counts and size on disk.

xod stats data/app.xod
xod stats data/app.xod --password-env XOD_PASSWORD

convert

Converts a database to another format, writing the converted files to the target folder.

xod convert data data-json --format json
xod convert data data-binary --format binary --password-env XOD_PASSWORD

--format takes xml, json or binary (default json); any other value is refused. This runs XodMigrator (see Storage formats).

The conversion is refused while another context or process has the source open, and the target must be a new or empty folder (pass the source folder as the target to convert in place). Before converting, it recovers any interrupted write or database a crash set aside in the source, as an open does.

secure

Adds a password to a database.

xod secure data/app.xod --password-env XOD_PASSWORD

loose

Removes the password.

xod loose data/app.xod --password-env XOD_PASSWORD

secure and loose fail while another context has the database open or if crash leftovers are waiting in the folder. loose is also refused when the database holds [Crypto(AES256)] values whose key the password protects, since the tool can’t pass DatabaseOptions.PropertyEncryptionKey to take over protection — remove the password from code instead (see Encrypting a property).

query

Runs a SQL SELECT (see Querying with SQL) and prints the rows without needing your application’s classes: each table is read from the schema recorded in its table file.

xod query data/app.xod "SELECT Category, COUNT(*) AS n FROM Product GROUP BY Category ORDER BY Category"
xod query data/app.xod "SELECT Id, Status FROM \"Order\" ORDER BY Id" --format json
xod query data/app.xod "SELECT Name FROM Customer" --password-env XOD_PASSWORD --format csv

The first prints:

Category | n
---------+--
garden   | 3
kitchen  | 3
office   | 4
toys     | 4
NULL     | 1
(5 rows)
  • --format takes table (default), csv or json. csv leaves NULL empty. json writes {"columns": [...], "rows": [...], "warnings": [...]}, encoding INTEGER values beyond 2^53 and every DECIMAL as strings so JSON parsers don’t lose precision.
  • Read-only: writes no rows and creates no database. Like any open, it recovers an interrupted commit first.
  • A table without a recorded schema is read with every column as text (warning XQ013) until any write by your application records its schema.
  • An encrypted column reads as NULL (warning XQ008) unless the password opens its key. A key protected by DatabaseOptions.PropertyEncryptionKey can’t be provided on the command line.
  • Warnings go to standard error. Errors print their code and message (XQ004: no column named Nme) and exit with 1.

Help and exit codes

xod --help (or -h, or help) lists all commands. The tool exits with 0 on success and 1 on error, and writes UTF-8 when output is redirected to a file or pipe.

Source on GitHub · Report a problem with this page