Skip to main content

Save Tables in a Database

With the wvlet CLI, you can keep query results as tables in a database folder on your machine. You don't need a server or any setup. You can list the database's tables, see every version of a table, and read a table as it was before a change.

note

Databases need the Homebrew or release-package wvlet (the JVM CLI). The npm package, the native CLI, and the playground don't open them yet.

Create a database and save a table​

Save this as setup.wv and run wvlet run -f setup.wv, or type the lines in the shell:

create database 'data/mydb' if not exists
use mydb

from [[1, 'apple', 120], [2, 'banana', 80]] as t(id, name, price)
save to products
  • create database makes a database in the folder data/mydb and names it mydb, after the folder. With if not exists, the same script also works on later runs: it opens the database that is already there.
  • use mydb makes it the current database, so products means mydb.products.
  • save to products creates the table, or replaces its rows if it exists.

Add and delete rows​

from [[3, 'cherry', 300]] as t(id, name, price)
append to products

from products
where name = 'banana'
delete

append to adds rows to a table. delete removes the rows that the query above it selects, so run the query without delete first to check them.

List databases and tables​

In the same session:

show databases -- the connector's catalog (wvlet) and mydb
show tables in mydb -- products
describe products -- its columns and types

See a table's versions​

Each write is a new version of the database. show versions in lists the versions that changed a table, newest first:

show versions in products
┌─────────┬────────────────────────────┬────────┬───────────┬────────┐
│ version │ time │ change │ row_count │ author │
│ long │ timestamp │ string │ long │ string │
├─────────┼────────────────────────────┼────────┼───────────┼────────┤
│ 3 │ 2026-12-04 23:33:55.957+00 │ update │ 2 │ wvlet │
│ 2 │ 2026-12-04 23:33:55.494+00 │ append │ 3 │ wvlet │
│ 1 │ 2026-12-04 23:33:53.3+00 │ create │ 2 │ wvlet │
├─────────┴────────────────────────────┴────────┴───────────┴────────┤
│ 3 rows │
└────────────────────────────────────────────────────────────────────┘

The top row is the table's current version. Earlier versions stay readable, so you can see the rows before the delete:

from products at version 2

Open the database again​

In a new session or script, open the database by its folder:

import database 'data/mydb' -- fails if the folder holds no database
use mydb
from products

Next steps​

  • L-Store covers snapshots, clones, branches, transactions, and making a database your profile's default.
  • Managing Tables and Schemas covers create table, drop table, truncate, and rename table.