The shell

Open a database file and run FennecQL on it, one statement at a time. It is the quickest way to learn the language, and to look inside a file a server or an app keeps.

Quickstart

fennec comes beside fennec-server in every way of installing it (Install), and the steps below need nothing else. Give it a file of its own, scratch.fennec here: not one a server has open, such as the Quickstart's notes.fennec, since two processes writing one file would corrupt it: the shell refuses a file another process has open (The file's lock).

  1. Open a file. It is made if there is none.

    fennec scratch.fennec
    prints
    fennecdb 0.2.0 — scratch.fennec
    `.help` for help, `.quit` to exit
  2. At the prompt, make a collection, each field typed and the ones you filter, order and search by indexed, and write two rows. A write ends at a ;.

    fennec> create collection notes (title text @text, year int @sorted)
    collection `notes` created
    fennec> put notes [{title: "Dunes", year: 2021}, {title: "Night at the oasis", year: 2024}];
    2 records (133.38µs)
  3. Read them back by a filter and an order, then search the words, a typo and all. The timings are yours.

    fennec> get notes where year >= 2020 order year desc
    id  title               year
    --  ------------------  ----
    2   Night at the oasis  2024
    1   Dunes               2021
    (2 rows, 149.12µs)
    fennec> get notes select title match title "oasys" fuzzy
    title               _score
    ------------------  ------
    Night at the oasis  0.6224
    (1 rows, 27.33µs)
    fennec> .quit

The file is the database: fennec scratch.fennec opens it again with its rows, and fennec-server --file scratch.fennec serves it once the shell has quit. FennecQL is a tour of the language in this shell, from a first write to a lookup and a total.

Running statements

fennec scratch.fennec                        # interactive
fennec scratch.fennec -c 'get notes limit 5' # one statement, then exit
echo 'get notes' | fennec scratch.fennec     # from a pipe
fennec scratch.fennec < seed.fennecql           # a script
fennec --read-only notes.fennec              # a server's file, read beside it
fennec --version                             # fennec <version>, and nothing opened

--version, or -V, prints the shell's version on stdout and exits 0 without opening a file; fennec version, with no dashes, opens a file named version, as any other word does. Releases up to 0.1.12 have no --version: the first line an interactive session prints names theirs.

The shell holds <file>.lock while it has a file open, as fennec-server --file, a --dir node for each tenant it has open, fennec mcp --file and an app through the native library do, so a file one of them or another shell has open is refused, and its holder named — notes.fennec is open in another process (fennec-server, pid 4242), exit 1. A server's file is queried over HTTP instead, or the server stopped first; a file another session or an app has open is closed there first. -c, a pipe and a script are refused alike, and so are fennec import into the file, a backup or restore into it and .save over it. Where the lock cannot be taken at all, in a directory you may only read, the refusal points to --read-only, which takes no lock and writes nothing: it reads the file as it stood at the open, beside a server writing it, and refuses every write and .checkpoint. It maps the file up to where the server last made it durable and reads the rest into memory, so a server starting beside it neither waits for it nor ends it; fennec types and fennec mcp --read-only open a file the same way. That memory has no bound but the file: the writes since the server's last sync, up to 128 KB before them and the record holding that point whole — a graph the server kept in the file, a block of up to 16 MB, the spills of a block still open; under --sync off, running or crashed, every write since the server opened the file or last compacted it; after a crash, the torn tail a server opening the file cuts; all of the file past its first image, when no sync ever made it durable past it (an app's file written and closed with no sync). A file with nothing past its image — what a compact, a checkpoint, .save and a backup write — is mapped whole and none of it read into memory. On Windows the reader's mapping keeps a server from cutting that tail: a server opening a file a crash left torn fails, naming the file, until --read-only is closed. A file opened through a symbolic link is the file the link leads to, for its lock and for the checkpoints and compacts that write it anew, the link left a link; a hard link, a Docker Desktop bind mount and a network file system keeping no locks are not seen through, so open a file from one side of those only. On Linux, after the machine went down and before a server or the shell opens the file to write it again, it may lack the last durable writes: they wait in the sync log beside the file, which only an open to write plays back. Releases up to 0.1.12 took no lock, and a write there beside a running server could leave the file unreadable.

Opened to be written, a file loses what a crash left beside it — a compact's .beside, a checkpoint's .compacting, a replica's .taking, a .save's .saving, each as large as the live data, a compact's .sorting on Windows — and the shell says so on stderr, a line each, in a server's words: notes.fennec.beside: removed, 4096 bytes a process writing notes.fennec left beside it as it ended. A file at such a name with a lock file beside it is a database of its own and stays, said at every open (notes.fennec.saving: kept: a lock file beside it, …) until it and its lock file are deleted by hand. --read-only removes nothing and says nothing (how a compact rewrites the file).

Inside the shell, a line that begins with a . is the shell's own:

CommandWhat it does
.helpthe summary of FennecQL and of these commands
.tablesthe collections
.statsstorage statistics: each collection's documents, the bytes of its live records and of the dead ones compact gives back, its segments and vector indexes
.functionsthe registered functions and plugins
.save <path>writes a snapshot of the database to a file
.checkpointrewrites the file and saves the vector graphs in it, so the next open is fast
.quitexits

Statements over several lines

A statement may run over several lines, and the shell runs it only once nothing after it can go on with it. Typed, a read or a schema change written on one line runs at Enter. A write, and a read written over several lines, wait for the next line: one that goes on with them — where, order, and — joins them, and an empty line or another statement runs them first. describe statement waits too, since a name on the next line makes it a named statement's, and so does a call whose arguments may come on the next line. A definition's body of several, as begin … end, is one statement: its ;s run nothing, and the Enter after its end runs it (a case's own end closing the case). .help gives the forms of a definition and a call beside the rest of FennecQL. A ; after a statement runs it at once. So del notes with where id = 3 on the line under it deletes one row. A . command leaves a waiting statement waiting — .tables to look a name up before the where — and .quit leaves it unrun.

Ending each write with a ;, as the session above does, is the habit that behaves the same everywhere, including in releases up to 0.1.10: they run every line whose brackets close, so there del notes deletes every row before a where under it is refused.

How a pipe, a paste and -c are read

Piped from a file, a statement runs once the next one begins, and a paste is read the same way, its lines all there at once — a . command in either waits behind the statement before it, and runs once that has. -c reads its text whole, as POST /query does, so a text that does not parse runs nothing. A line that begins no statement — a where after a read that already ran at Enter, a wher mistyped, a clause written past a ; — is refused, and so is the statement before it, which it may have meant to go on with: del notes; where id = 3 deletes nothing.

A paste the terminal delivers in pieces further apart than 40 ms is read as typed lines, and a pasted statement whose last line has no newline yet waits for Enter like a typed one.

What else the program does

The same fennec is the tool for a file or a server beyond the prompt. fennec --help lists each, and fennec <command> --help the flags that command reads.

  • fennec import copies a SQLite file or a PostgreSQL table into a collection, and --follow keeps a PostgreSQL copy up to date: Import.
  • fennec backup, archive, restore, prune and verify take a running server whole, keep its writes and rebuild it as it stood at a moment, and fennec key makes the key that seals them: Replication.
  • fennec types writes TypeScript, Python, Go, C#, Swift, Kotlin or Dart types for its collections and named statements, from a database file: TypeScript.
  • fennec mcp serves a file, or a server, to an agent over stdio: Agents and MCP.

Each command reads its own flags alone: one it does not read — another command's among them — is refused, as is a flag missing its value; and every refusal of the line — an argument missing, a flag the command needs, a malformed URL, a token not given — comes before anything a flag names (--tls-ca's CAs, --key-file's key) is opened, read or made. Its exit code says how it ended: 0 when it did what it was asked (or printed --help or --version); 1 when its work failed — a statement of -c, a file that cannot be opened or synced or whose lock another holds, an import, a backup, an archive or a restore, a verify finding what cannot be restored, a key fennec key cannot make (the system giving it no randomness) or write, the file fennec types reads or the one it writes; 2 when the line was refused before anything ran — a flag, a value or an argument, a file it would write over without --force, or a subcommand this build was made without.