Skip to main content

Quickstart

Get Databas running on your machine and execute your first SQL queries.

Prerequisites

You need Rust installed on your system. If you don’t have it, install it from rustup.rs. Verify your installation:
rustc --version

Clone the repository

1

Clone from GitHub

Clone the Databas repository to your local machine:
git clone https://github.com/writemorecode/databas.git
cd databas
2

Build the project

Build all workspace crates using Cargo:
cargo build --release
This compiles three crates:
  • databas_cli - Command-line interface
  • databas_core - Database engine
  • databas_sql_parser - SQL parser
The compiled binary will be located at target/release/databas_cli.
3

Run the CLI

Start the interactive REPL:
cargo run --bin databas_cli
You should see the >>> prompt:
>>>

Your first queries

The current version parses SQL statements and displays the parsed output. Try these examples in the REPL:

Create a table

>>> CREATE TABLE products (id INT PRIMARY KEY, name TEXT, price FLOAT);
Output:
'CREATE TABLE products (id INT PRIMARY KEY, name TEXT, price FLOAT);'

Insert data

>>> INSERT INTO products (id, name, price) VALUES (123, 'Cake', 45.67);
Output:
'INSERT INTO products (id, name, price) VALUES (123, 'Cake', 45.67);'
You can insert multiple rows in one statement:
>>> INSERT INTO products (id, name, price) VALUES (123, 'Cake', 45.67), (789, 'Waffles', 10.00);

Query data

>>> SELECT name, price FROM products WHERE price > 10.00 ORDER BY price DESC;
Output:
'SELECT name, price FROM products WHERE price > 10.00 ORDER BY price DESC;'

Use expressions

The parser supports arithmetic expressions and operators:
>>> SELECT id * 2, price + 5.00 FROM products;

Exit the REPL

Type exit to quit:
>>> exit

Single query mode

You can execute a single query without entering the REPL by passing it as an argument:
cargo run --bin databas_cli "SELECT * FROM products WHERE id = 123;"

Understanding the output

The CLI currently displays the parsed SQL statement as a string representation. This demonstrates that the parser successfully:
  1. Tokenized the input SQL into tokens (keywords, identifiers, operators, literals)
  2. Parsed the tokens into an abstract syntax tree (AST)
  3. Validated the SQL syntax structure
  4. Formatted the AST back to a normalized SQL string
From the source code in crates/databas_cli/src/main.rs:4-15:
fn run(buf: String) {
    let parser = Parser::new(&buf);
    for tree in parser {
        match tree {
            Ok(t) => println!("'{t}'"),
            Err(err) => {
                eprintln!("ERROR: {err}");
                return;
            }
        }
    }
    println!();
}

Supported SQL features

The parser currently supports:

Data types

  • INT - Integer values
  • FLOAT - Floating-point numbers
  • TEXT - String values

Constraints

  • PRIMARY KEY
  • NULLABLE

Statements

  • SELECT with columns and wildcards
  • INSERT with single or multiple rows
  • CREATE TABLE with column definitions

Clauses

  • WHERE with expressions
  • ORDER BY with ASC/DESC
  • LIMIT and OFFSET

Error handling

If you enter invalid SQL, the parser will report an error with position information:
>>> SELECT FROM products;
Output:
ERROR: Expected expression at position ...

Next steps

Architecture

Learn about the database internals

SQL Reference

Complete SQL syntax reference

Troubleshooting

Build errors

If you encounter build errors, make sure you have Rust edition 2024 support:
rustup update

Can’t find cargo command

Make sure Cargo is in your PATH:
export PATH="$HOME/.cargo/bin:$PATH"
Add this to your shell profile (.bashrc, .zshrc, etc.) to make it permanent.

Build docs developers (and LLMs) love