EveDB: the Eve Test Database
evedb, built next to the Eve virtual machine. When the machine is split into parts, it becomes the database part of eve itself, called with eve db. Its first job is to play the remote database in the tests of the Eve database layer: it speaks Eve's own protocol, keeps Eve's types without loss, and can fail on purpose, exactly when a test asks, so that commit, rollback and retry can be tested again and again with the same result.
serve, create, sql, describe, snapshot, reset, status and stop work. It is tested by 16 unit tests and by 66 checks of a Python client written from the design alone (python script/evedb_check.py). Not yet: the Eve driver evedb://, the change sets of the ORM, large results in batches, import and export, and service mode. The design is in evedb/README.md of the Eve repository.eve. SQLite stays embedded in eve; the DuckDB library is loaded only when the first DuckDB connection opens, so a script that uses no DuckDB database starts without it. The commands below become eve db serve, eve db sql and so on, and the database part also keeps the stored procedures written in Eve (Scripts, procedures and commands) and the SQL functions written in Eve (SQL functions in Eve).A PostgreSQL server for your tests
Since version 0.2 EveDB behaves like a PostgreSQL server. It listens on port 5432, accepts the login of a PostgreSQL client (no password, a password, or md5), runs the SQL with DuckDB, and answers rows, errors and transactions the way PostgreSQL does. Any PostgreSQL client connects to it: psql, psycopg2 in Python, JDBC, and the Eve driver for PostgreSQL.
A configuration file says which port, which login and which databases:
# evedb.cfg
port = 5432
user = "eve"
password = "secret"
auth = "md5"
database "shop" = "data/shop.duckdb"
Start it in one of three ways:
evedb serve --config evedb.cfg ** in this window
eve db serve evedb.cfg ** the same, started by eve
eve -s -db --serve evedb.cfg ** as a service: silent, in the background
A script reaches it like any PostgreSQL database. The connection is declared in eve.cfg with a postgres:// URL, and the methods are the ones you know from SQLite:
** eve.cfg
database "shop" = "postgres://eve:secret@127.0.0.1:5432/shop"
class Item = {id: Integer, name: String, price: Decimal} <: Record;
new shop := database.connect("shop");
shop.execute!("insert into items values (?, ?, ?)", 3, "washer", 0.10d);
for i in shop.query!(:Item)("select id, name, price from items order by id") do
print "{i.id} {i.name} {i.price}";
done;
The same driver connects to a real PostgreSQL server (it also speaks SCRAM-SHA-256, the login PostgreSQL uses by default). The mapped tables (table declarations) still need a SQLite connection. For large data inside Eve use the faster native connection of the next section.
The fast path: evedb:// and Memory tables
The PostgreSQL protocol is for other tools. Eve has a faster way to EveDB: the native protocol, with a URL that starts with evedb://. It sends large results column by column, in the same layout as a Memory table, so a column of a million numbers is copied in one piece instead of a million values written as text and read back.
** eve.cfg
database "wh" = "evedb://127.0.0.1:8044/warehouse"
class Sales = {id: Integer, region: String, amount: Real} <: Memory;
new wh := database.connect("wh");
new s := Sales();
s.store(wh, "select id, region, amount from sales where year = ?", 2026); ** column batches into s
print s.amount.sum();
s.load(wh, "sales_2026"); ** back, through DuckDB's bulk insert
Measured on one computer with 1,000,000 rows: store into a Memory table takes 0.23 s, three times faster than reading the same rows from a local SQLite file; a group-by over the whole table takes 9 ms in DuckDB and half a second in SQLite. Records (query!) cost about the same on every protocol, because each row becomes an object: use them for a few rows, and Memory tables for many.
Which database for what. SQLite, built into every eve, keeps the state of your project: checkpoints, run history, small lookup tables. DuckDB, inside the EveDB server, keeps the big data: warehouse tables, staging of large loads, large caches. One DuckDB database is one file (data/warehouse.duckdb, with its .wal log), and only EveDB opens it. Make one with evedb create warehouse, or name it in evedb.cfg. There are no triggers or stored procedures in EveDB: the logic lives in your Eve jobs, which work on whole tables at a time.
Why a test database
Eve has two database engines with two different roles:
| Engine | Role | Where it runs |
|---|---|---|
| SQLite | the core database of each project: the logs of the ETL runs, checkpoints, lineage, metadata and the data of the Eve UX. It never holds ETL data | inside the virtual machine, compiled into eve |
| DuckDB | EveDB, the database for data that Eve owns: staging tables of ETL, the cache of the Eve server, the tests; later analytics | in its own program, evedb |
A program that reads and writes a database on another machine has failures that a local database never shows: the network breaks before a commit, or after it; another program changed the row; the schema changed since the code was written. Eve handles these cases with jobs, recover and retry (see Processing and Databases). Each case needs a test, and each test needs a remote database. A real server such as PostgreSQL can play that role, but it must be installed, it can't be told to fail at the right moment, and it does not speak Eve. EveDB is made for that job:
- it starts on
localhostin a fraction of a second, with a fresh database for each test; - it speaks the Eve Wire Protocol, so no vendor driver is needed on the Eve side;
- it can drop a connection, refuse a commit or report a conflict on demand;
- it keeps a log of every statement it ran, so a test can check the SQL that Eve sent.
Where EveDB fits
The Eve database layer has three tiers. A local Eve program holds memory tables and reads files; an Eve server holds the sessions, the drivers and a cache; the remote database holds the data. EveDB stands in the place of the remote database, and also takes the server side of the sessions, so a test needs only eve and evedb:
+------------------------------+ +------------------------------+
| Eve program (eve) | EWP | EveDB (evedb) |
| memory tables, files, jobs | -------> | sessions, DuckDB, test log |
+------------------------------+ +------------------------------+
The program does not know which database it uses: the name of the connection is resolved by the configuration of the machine. The same script runs against SQLite, PostgreSQL or EveDB:
** eve.cfg of the machine that runs the tests (sketch)
database "shop" = "sqlite://db/shop.db" ** local: the embedded engine
database "sales" = "postgresql://etl@db1/sales" ** a real remote server
database "test" = "evedb://localhost/eve_test" ** the Eve test database
Why DuckDB
DuckDB is an embedded SQL database, like SQLite, but it stores tables column by column. EveDB uses it for what it gives for free:
- ACID transactions with several connections working at once: two transactions that change the same row conflict at the commit, which is exactly the case a test of optimistic locking needs;
- fast bulk loads: rows are appended in column batches, the same shape in which the Eve Wire Protocol sends a table;
- rich types: 128-bit integers, decimals of 38 digits, time stamps with a zone, intervals, UUIDs;
- upserts (
insert … on conflict do update), used by the bulk loads of ETL; - CSV, JSON and Parquet read and written in SQL, for test fixtures now and analytics later;
- one file per database, or a database in memory that a test creates and throws away in milliseconds.
EveDB is not meant to replace PostgreSQL in production: DuckDB is built for analytics, so many tiny transactions are slower than on a classic server. For tests and for bulk ETL that does not matter.
Tuned for Eve
The Eve Wire Protocol
EveDB listens on a TCP port and answers the database messages of the Eve Wire Protocol (see Protocols): open a session, begin a transaction, run a query and send the rows in batches, apply the changes of a flush, commit, roll back, and answer whether a transaction was committed. Only the fields that changed travel: an update of one field of a record with fifty fields sends one value, the key and the version. EveDB is the first program that implements the server side of these messages; the Eve server can reuse the same code later.
Eve types without loss
Every Eve type has a DuckDB column type that keeps it exactly, so a value written by Eve is read back the same:
| Eve | DuckDB |
|---|---|
Integer | BIGINT |
Natural | UBIGINT |
Huge (128 bits) | HUGEINT |
Decimal | DECIMAL(p, s) |
Real, Float | DOUBLE, FLOAT |
Logic | BOOLEAN |
String | VARCHAR |
Instant | TIMESTAMPTZ |
Date, Time, Duration | DATE, TIME, INTERVAL |
Uuid, Bytes | UUID, BLOB |
EveDB describes its tables in Eve types, so the check of a mapping (does every field of a record class have its column, with a type that fits?) is exact. evedb describe eve_test orders --eve prints the Eve record class of a table, ready to paste into a script.
Tables of Eve built in
A table exists in every EveDB database: eve_tx keeps the ids of the committed transactions. When the network breaks right after a commit, the program asks with that id and learns whether its work was saved. Eve installs no table of its own in a database that a DBA keeps, but EveDB is Eve's own and always exclusive: Eve may disable triggers and indexes there to load faster (prepare, activate, reindex). The checkpoints of long loads are not here: they are in the core database, and a load that commits in batches must be an upsert, so a batch loaded twice changes nothing.
Sessions and leases
Each process of an Eve program that uses the connection gets its own session, with its own DuckDB connection and its own transaction. A session has a lease: the program renews it while it works. When a program crashes, its lease runs out, EveDB rolls back the open transaction and frees the connection, so a dead program never holds locks for long.
Fault injection
The most useful feature of a test database is that it can fail on purpose. In test mode (evedb serve --test), a test arms a fault with a pragma statement, sent like any SQL; the fault fires once, at the next matching point:
| Fault | What happens | What it tests |
|---|---|---|
drop before or after the commit | EveDB closes the connection at that point | a lost connection is a transient error: retry; after the commit, the program asks and finds its work saved |
conflict on a table | the next update of that table conflicts | optimistic locking, ConflictError, a retry that reads fresh data |
deadlock | the next statement fails as a deadlock | DeadlockError, a pause before the retry |
commit_fail | the commit fails and rolls back | a job that fails at its end, with its memory restored |
delay | every message waits | time-outs and leases |
drift on a table | a column is added, changed or dropped | the mapping check: a warning for a harmless change, a hard stop for a wrong one |
** a test: the network breaks after the commit was sent
new test := database.connect("test");
test.execute!("pragma eve_fault('drop', 'after_commit')");
Outside test mode, a pragma eve_fault is an error: a production database never fails on request.
Statement log
In test mode EveDB writes every statement it runs to the table eve_log.statements: the session, the transaction, the kind of statement, the table, the columns written and the number of rows. A test reads it to prove what is otherwise invisible, for example that an update wrote only the field that changed:
** only the dirty field and the version were written
class Logged = {columns: String} <: Record;
new last := test.query_one!(:Logged)("select columns from eve_log.statements where kind = 'update' order by seq desc limit 1");
expect last != null and last.columns == "city,version";
Commands
| Command | Meaning |
|---|---|
evedb | print the versions and run the self-check (available now) |
evedb serve [--config evedb.cfg] [--port 5432] [--control-port 8044] [--data folder] [--test] [--lease seconds] [--token t] | listen; --test allows faults and the statement log and listens on localhost only; without --test a token is required; --port 0 lets the system choose and the first line says which |
evedb create name | create a database file in the data folder |
evedb sql [--connect host:port] name "statement" | run one statement and print the result, on the file or through a server |
evedb describe name table | the columns in Eve types |
evedb snapshot name file, evedb reset name file | save a database and put it back, for test fixtures |
evedb status, evedb stop | the counters of a server (databases, sessions, open transactions, statements, uptime); end a server |
evedb import, evedb export | load or write a table as CSV, JSON or Parquet (version 0.2) |
With the split of the machine every command is written with eve db in front instead of evedb: eve db serve --test, eve db describe shop orders --eve. Two commands are added for the stored procedures written in Eve: eve db proc list and eve db proc reload. In the Eve repository, ./run.sh evedb … is the shortcut for bin/eve db ….
The test runner of Eve starts evedb serve --test with a fresh data folder before the database tests, resets the fixtures before each test that uses the connection "test", and stops it at the end.
Build and run
EveDB lives in the folder evedb/ of the Eve repository, next to the virtual machine in evevm/, and is written in Zig 0.16 like the machine. DuckDB is not copied into the repository: the build downloads the prebuilt library of the system once, checks it against its hash, and keeps it in a cache.
cd evedb
zig build -p .. # installs bin/evedb.exe and bin/duckdb.dll, next to bin/eve.exe
zig build test # the unit tests
../bin/evedb.exe
evedb 0.1.0, DuckDB v1.5.6, self-check 42
../bin/evedb.exe serve --test --port 0 --data ../temp/edata
evedb: listening on port 59896 (test mode)
python ../script/evedb_check.py # the protocol checks, from the repository root
The same build gives SQLite to the machine: evevm/ compiles the SQLite source into eve, so the core database needs no installation at all.
After the split, evedb/ is one module of a single build at the root of the repository, next to evecm/, evecp/, evevm/ and eveux/: zig build -p . installs bin/eve.exe and the DuckDB library, and there is no bin/evedb.exe any more.
Inside the project
| File | Content |
|---|---|
build.zig, build.zig.zon | the build and the pinned DuckDB library of each system |
src/main.zig | the command line |
src/duckdb.zig | the binding over the C interface of DuckDB (written) |
src/server.zig | the listener, the frame loop of a connection, sessions and their leases, transactions and STATUS, the statement log (written) |
src/ewp.zig | the frames and the values of the Eve Wire Protocol for databases (written) |
src/types.zig, src/cells.zig | Eve types, error classes, the reading of the cells of a result (written) |
src/fault.zig | fault injection (written) |
src/client.zig | a client of the frames, for --connect (written) |
src/changes.zig | the changes of a flush turned into SQL (planned, 0.2) |
Versions
| EveDB | With Eve | Content |
|---|---|---|
| 0.1 (built, 2026-10-17) | 0.5 (server, level 6) | the test server: sessions and leases, the protocol, Eve types, STATUS after a broken commit, seven faults, statement log, snapshots, a token |
| 0.2 | 0.5 (server) | change sets and large results, bulk loads and upserts, import and export, service mode (evedb serve -s), the protocol code shared with the Eve server |
| later | an analytic database for Eve: Parquet, large aggregates, users and rights |
Read next: Index