DEV Community

Cover image for LioranDB TypeScript Series #10: Mastering the Official LioranDB CLI
Swaraj Puppalwar
Swaraj Puppalwar

Posted on

LioranDB TypeScript Series #10: Mastering the Official LioranDB CLI

LioranDB TypeScript Series #10: Mastering the Official LioranDB CLI

LioranDB TypeScript Series: Build with a developer-first document database powered by Rust and designed for TypeScript.

Not everything needs a dashboard.

Sometimes you just want a terminal and a database that listens.

Meet the official LioranDB CLI.

Install

npm install -g @liorandb/cli@1.0.5
Enter fullscreen mode Exit fullscreen mode

The executable is:

liorandb
Enter fullscreen mode Exit fullscreen mode

Initialize

liorandb init
Enter fullscreen mode Exit fullscreen mode

Configure a connection:

liorandb set url \
  "liorandb://admin:YOUR_PASSWORD@127.0.0.1:27018/default"
Enter fullscreen mode Exit fullscreen mode

Authenticate:

printf '%s' "$LIORANDB_PASSWORD" |
liorandb login admin --password-stdin
Enter fullscreen mode Exit fullscreen mode

Select a database

liorandb db use default
Enter fullscreen mode Exit fullscreen mode

Create a collection:

liorandb collection create products
Enter fullscreen mode Exit fullscreen mode

Insert from stdin

printf '{"sku":"bk-001","title":"Blue Notebook","active":true}' |
liorandb insert-one products --stdin
Enter fullscreen mode Exit fullscreen mode

Count:

liorandb count products
Enter fullscreen mode Exit fullscreen mode

Then jump into the interactive shell:

liorandb shell
Enter fullscreen mode Exit fullscreen mode

Profiles

The CLI supports local profiles, which makes switching environments much less painful.

Think:

local
staging
production
client-a
client-b
Enter fullscreen mode Exit fullscreen mode

instead of repeatedly pasting connection information.

Output formats

Automation doesn't want pretty tables.

Humans often do.

The CLI supports output modes including:

table
json
ndjson
quiet
Enter fullscreen mode Exit fullscreen mode

Global flags include:

--profile
--url
--output
--json
--quiet
--no-color
--debug
Enter fullscreen mode Exit fullscreen mode

What can the CLI control?

Quite a lot.

Data

db
collection
find
find-one
insert-one
update-one
delete-many
aggregate
count
Enter fullscreen mode Exit fullscreen mode

Indexes

index list
index create
index create-text
index drop
Enter fullscreen mode Exit fullscreen mode

Authentication

login
logout
whoami
sessions
change-password
Enter fullscreen mode Exit fullscreen mode

Administration

user
role
settings
cors
Enter fullscreen mode Exit fullscreen mode

Operations

status
health
doctor
metrics
cluster
backup
Enter fullscreen mode Exit fullscreen mode

Safety

Destructive commands should be difficult to trigger accidentally.

Operations such as drops, broad deletions and backup restore/delete flows use confirmation mechanisms unless explicitly overridden where supported.

That's intentional.

A CLI should help you operate the database, not speedrun deleting Tuesday.

Local state

CLI state is stored under:

.liorandb/state
Enter fullscreen mode Exit fullscreen mode

You can override the location with:

LIORANDB_STATE_DIR
Enter fullscreen mode Exit fullscreen mode

Passwords are not persisted as ordinary stored profile values.

CLI + Driver

The CLI and TypeScript driver aren't competing interfaces.

A common setup is:

Application code
    → @liorandb/driver

Developers / CI / Operations
    → @liorandb/cli
Enter fullscreen mode Exit fullscreen mode

Use each where it fits best.

Resources

CLI Documentation:
https://docs.liorandb.com/docs/cli/overview

Documentation: https://docs.liorandb.com
Website: https://liorandb.com


Previous: Part 9 → Operations & Backups
Next: Part 11 → Docker Compose, Caddy & TLS


Enter fullscreen mode Exit fullscreen mode

Top comments (0)