Getting Started

Install PowDB, create a table, insert data, query it, and run in server mode. Takes about 10 minutes.

1Install

The easiest way to install PowDB is from crates.io:

cargo install powdb-cli
cargo install powdb-server

Or build from source (requires Rust 1.80+; install from rustup.rs if needed):

git clone https://github.com/zvndev/powdb.git
cd powdb
cargo build --release

Check that installation worked:

powdb-cli --version

2Start the REPL

Launch the interactive PowQL shell:

powdb-cli
# or from source:
cargo run --release -p powdb-cli

You should see:

PowDB v0.2.0 -- embedded mode Data directory: ./powdb_data Type PowQL queries. Use Ctrl-D to exit. powql>

Data is stored in ./powdb_data/ by default. Change it with --data-dir:

powdb-cli --data-dir ./my_project_data

3Create a Table

PowDB uses the type keyword to define tables. Fields prefixed with required cannot be null.

powql> type User { required name: str, required email: str, age: int }
type User created

No CREATE TABLE, no column types in parentheses. Fields have a name and a type, separated by a colon.

Supported types: str, int, float, bool, datetime, uuid, bytes.

4Insert Data

Insert rows with the insert keyword. Fields are assigned with :=.

powql> insert User { name := "Alice", email := "alice@example.com", age := 30 }
1 row affected

Add a few more people:

powql> insert User { name := "Bob", email := "bob@example.com", age := 25 }
powql> insert User { name := "Charlie", email := "charlie@example.com", age := 35 }
powql> insert User { name := "Diana", email := "diana@example.com", age := 28 }
powql> insert User { name := "Eve", email := "eve@example.com", age := 22 }
powql> insert User { name := "Frank", email := "frank@example.com", age := 40 }

Fields without required can be omitted -- they default to null:

powql> insert User { name := "Grace", email := "grace@example.com" }
1 row affected

5Query Basics

Select all rows

Just type the table name:

powql> User
name | email | age ---------+----------------------+---- Alice | alice@example.com | 30 Bob | bob@example.com | 25 Charlie | charlie@example.com | 35 Diana | diana@example.com | 28 Eve | eve@example.com | 22 Frank | frank@example.com | 40 Grace | grace@example.com | NULL (7 rows)

Filter rows

Use filter with a condition. Fields are referenced with a dot prefix:

powql> User filter .age > 25
name | email | age ---------+----------------------+---- Alice | alice@example.com | 30 Charlie | charlie@example.com | 35 Diana | diana@example.com | 28 Frank | frank@example.com | 40 (4 rows)

Project specific fields

Use { } braces to select which fields to return:

powql> User filter .age > 25 { .name, .age }
name | age ---------+---- Alice | 30 Charlie | 35 Diana | 28 Frank | 40 (4 rows)

6Sorting and Limiting

PowQL operations chain left to right in a pipeline. Add order and limit:

powql> User order .age desc limit 3 { .name, .age }
name | age ---------+---- Frank | 40 Charlie | 35 Alice | 30 (3 rows)

7Aggregations

PowQL wraps aggregate functions around the query pipeline.

powql> count(User)
7

powql> count(User filter .age > 25)
4

powql> avg(User { .age })
30

powql> sum(User filter .age > 25 { .age })
133

Other aggregate functions: min(), max().

8Updates

Use update after an optional filter to modify rows:

powql> User filter .name = "Alice" update { age := 31 }
1 row affected

Verify it worked:

powql> User filter .name = "Alice" { .name, .age }
name | age -------+---- Alice | 31 (1 row)

You can use expressions that reference the current row value:

powql> User filter .name = "Bob" update { age := .age + 1 }

9Create an Index

Indexes speed up lookups on frequently queried columns:

powql> alter User add index .email
index on 'User.email' created

Indexed columns are used automatically for point lookups and range scans -- no query hints needed.

10Delete

Use delete after a filter to remove matching rows:

powql> User filter .age < 25 delete
1 row affected

To delete all rows in a table: User delete

11Server Mode

For multi-client access, run PowDB as a server.

Start the server

powdb-server --port 5433 --data-dir ./powdb_data
powdb server listening addr=127.0.0.1:5433 data_dir=./powdb_data auth=false ...

Connect from a client

powdb-cli --remote localhost:5433
PowDB v0.2.0 -- remote mode Connecting to localhost:5433 ... Connected to db `main` (server v0.2.0) Type PowQL queries. Use Ctrl-D to exit. powql>

From here, the same PowQL statements work as embedded mode.

TypeScript client

import { Client } from "@zvndev/powdb-client";

const client = await Client.connect({ host: "localhost", port: 5433 });
const result = await client.query("User filter .age > 25 { .name, .age }");
if (result.kind === "rows") console.table(result.rows);

Password authentication

# Start the server with a password
POWDB_PASSWORD=mysecret powdb-server

# Connect with the password
powdb-cli --remote localhost:5433 --password mysecret

What's Next

This tutorial covered tables, inserts, queries, aggregates, updates, indexes, deletes, and server mode. PowDB supports much more, including joins, group by, subqueries, materialized views, window functions, and set operations.

See the full language reference: PowQL Reference