Skip to content
NarDBv0.2.0-dev

Command line

nardb create, user, grant, serve — managing databases and users from the terminal.

nardb is a single program. Run without arguments, it opens the full-screen NarDB Shell; run with a command, it does the command and exits without opening the interface.

Terminal
nardb create shop                         # asks for the root password
nardb user add shop app                   # asks for app's password
nardb grant shop app members write
nardb user list shop
nardb serve                               # 127.0.0.1:7070

Database: path or name#

Every command takes a <db>:

Written asDatabase
shop~/.nardb/data/shop.ndbc — the database served by nardb serve
./data/app.ndbcthe folder at that path — an application's embedded database

Anything containing a slash or ending in .ndbc is a path. A name has lowercase letters, digits, _ and -, and starts with a letter. To use another directory than ~/.nardb, set the NARDB_HOME environment variable.

Commands#

CommandWhat it does
`nardb create <db> [-e keychain\passphrase\none]`Creates the database and its root user. Default encryption: key in the system keychain.
nardb user add <db> <name>Adds a user. It has no permissions; give them with grant.
nardb user passwd <db> <name>Changes a password.
nardb user list <db>Users and their grants.
nardb user delete <db> <name>Deletes a user and its grants. root cannot be deleted.
`nardb grant <db> <user> <schema\*> <read\write\admin>`Gives or changes a permission.
`nardb revoke <db> <user> <schema\*>`Removes a permission.
nardb serveServes databases over the network; see Server.
nardb certs · nardb client-certCertificates for clients on other machines.
nardb help · nardb version

Quote '*' so the shell does not expand it.

Passwords are not arguments#

There is no nardb user add shop app secret: a password typed on the command line ends up in the shell history and in ps output. The password is:

  • asked twice, hidden, in a terminal;
  • read as one line from standard input when there is no terminal:
Terminal
printf '%s\n' "$ROOT_PASSWORD" | nardb create shop -e none

User passwords need at least 8 characters, encryption passphrases at least

  1. When a passphrase-encrypted database is opened, the passphrase is asked

or read from the NARDB_PASSPHRASE environment variable.

A database that is open#

Only one process can open a .ndbc at a time. While nardb serve, NarDB Shell or a LexerLang application has the database open, a command fails with:

Text
nardb: ~/.nardb/data/shop.ndbc is open in another process (nardb serve, NarDB Shell or an app); stop it first

Stop the server briefly to change users and grants.

nardbd#

nardbd is the server's old name and accepts the same commands: nardbd serve -config nardbd.json keeps working.