Developer beta 0.1.0-beta.1 documentation. These pages describe the beta as built and tested on Linux x86-64. See the beta page for what is available today.

Tutorial: a hotel in twenty minutes

This tutorial builds one small database from nothing and uses most of what the beta offers: a table, an index, queries, a transaction, the server, a user, a program, Studio and a backup. Every statement is inside the supported SQL subset.

You need the holadb command (Installation).

1. Create the database

A database is a directory.

holadb init ./hotel

2. Create a table and add rooms

holadb query ./hotel "
  CREATE TABLE hotel_rooms (room_id INTEGER PRIMARY KEY, room_type TEXT NOT NULL, price INTEGER NOT NULL, floor INTEGER DEFAULT 1);
  INSERT INTO hotel_rooms VALUES
    (101, 'single', 80, 1), (102, 'double', 120, 1), (103, 'double', 120, 1),
    (201, 'suite', 260, 2), (202, 'double', 130, 2), (203, 'single', 85, 2);
"

query opened the directory directly; no server is running yet. Only one process may have a directory open at a time.

3. Ask questions

Open the interactive shell:

holadb shell ./hotel
SELECT room_id, room_type, price FROM hotel_rooms WHERE price < 125 ORDER BY price, room_id;
SELECT room_id FROM hotel_rooms WHERE room_type = 'double' AND floor = 2;
SELECT room_id, price FROM hotel_rooms ORDER BY price DESC LIMIT 3;
SELECT count(*), min(price), max(price), avg(price) FROM hotel_rooms;
SELECT count(*) FROM hotel_rooms WHERE room_type LIKE 's%';

\d hotel_rooms describes the table and \q leaves the shell.

Two things this beta does not do, so you are not surprised: there is no GROUP BY and no JOIN. Aggregates work over a whole table or a WHERE selection. The full list is under What is not supported.

4. Change data

UPDATE hotel_rooms SET price = price + 10 WHERE room_type = 'suite';
DELETE FROM hotel_rooms WHERE room_id = 203;
INSERT INTO hotel_rooms (room_id, room_type, price) VALUES (204, 'single', 85);

Room 204 gets floor = 1, the column’s default.

A write that breaks a rule is refused, never adjusted:

INSERT INTO hotel_rooms VALUES (101, 'single', 80, 1);   -- duplicate primary key
INSERT INTO hotel_rooms VALUES (301, NULL, 90, 3);       -- NULL into a NOT NULL column

5. Use a transaction

Several statements that must succeed or fail together go between BEGIN and COMMIT:

BEGIN;
UPDATE hotel_rooms SET price = price - 5 WHERE floor = 1;
UPDATE hotel_rooms SET price = price + 5 WHERE floor = 2;
COMMIT;

ROLLBACK instead of COMMIT discards both changes. If a statement fails inside a transaction, the transaction is aborted and only ROLLBACK is accepted. See Transactions.

6. Add an index and read a plan

EXPLAIN SELECT * FROM hotel_rooms WHERE room_id = 101;
CREATE INDEX hotel_rooms_type ON hotel_rooms (room_type);
EXPLAIN SELECT * FROM hotel_rooms WHERE room_type = 'double';

The first plan is a PointLookup on the primary key. After the index exists, the second is an IndexLookup; without it, it would be a TableScan with a Filter. SQL lists the plan nodes.

7. Serve it

Leave the shell (\q), then:

holadb serve ./hotel --listen 127.0.0.1:7433 --pg 127.0.0.1:5433

Port 7433 speaks HolaDB’s native protocol (the SDKs, Studio and the CLI’s remote mode). Port 5433 speaks the PostgreSQL protocol for psql.

In another terminal:

holadb query holadb://127.0.0.1:7433 "SELECT count(*) FROM hotel_rooms"
psql postgresql://me@127.0.0.1:5433/holadb -c "SELECT room_id, price FROM hotel_rooms ORDER BY price"

8. Turn authentication on

A fresh database is open to whoever can reach it. Creating the first user turns authentication on and makes that user an administrator:

holadb query holadb://127.0.0.1:7433 "CREATE USER admin WITH PASSWORD 'change-me-now'"
holadb query holadb://admin:change-me-now@127.0.0.1:7433 "CREATE USER frontdesk WITH PASSWORD 'desk-secret' ROLE readwrite"

frontdesk can read and write rows but cannot create, alter or drop tables. See Security.

9. Use it from a program

Python (Python SDK):

import holadb

with holadb.connect("holadb://frontdesk:desk-secret@127.0.0.1:7433") as db:
    for row in db.query("SELECT room_id, price FROM hotel_rooms WHERE price < $1", [125]):
        print(row["room_id"], row["price"])
    db.execute("UPDATE hotel_rooms SET price = $1 WHERE room_id = $2", [125, 102])

The TypeScript SDK and the Rust SDK follow the same shape: connect, query with numbered parameters, read rows.

10. Look at it in a browser

HOLADB_PASSWORD=change-me-now holadb studio holadb://admin@127.0.0.1:7433

Open http://127.0.0.1:7480/, run a query in the SQL tab and open hotel_rooms in Browse. See Studio.

11. Back up and restore

While the server runs, take an online backup, check it and restore it into a new directory:

holadb snapshot holadb://admin:change-me-now@127.0.0.1:7433 ./backups/hotel-1
holadb verify-backup ./backups/hotel-1
holadb restore ./backups/hotel-1 ./hotel-copy
holadb query ./hotel-copy "SELECT count(*) FROM hotel_rooms"

The backup path is on the server’s machine. With the server stopped, holadb backup ./hotel ./backups/hotel-2 does the same offline. See Backup and Restore.

Where next