Crate otter_sql

Source
Expand description

OtterSQL

๐Ÿฆฆ An Embeddable SQL Executor in Rust

See README for more details.

This crate documentation describes the public API of OtterSQL. See above if you only want to use the CLI.

ยงInstallation

Add the following to your Cargo.toml

otter-sql = "0.1"

ยงGetting started

use otter_sql::VirtualMachine;

fn main() {
    // initialize an OtterSQL VM
    let mut vm = VirtualMachine::default();

    // execute SQL!
    vm.execute(
        "
        CREATE TABLE table1
        (
            col1 INTEGER PRIMARY KEY NOT NULL,
            col2 STRING NOT NULL
        )
        ",
    ).unwrap();

    // insert some values
    vm.execute(
        "
        INSERT INTO table1 VALUES
            (2, 'bar'),
            (3, 'aaa')
        ",
    ).unwrap();

    // two unwraps because this returns a `Result<Option<Table>, ...>`.
    let res = vm.execute("SELECT * FROM table1").unwrap().unwrap();

    println!("{}", res);
}

Output:

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ col1 โ”‚ col2 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 2    โ”‚ bar  โ”‚
โ”‚ 3    โ”‚ aaa  โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Re-exportsยง

pub use column::Column;
pub use database::Database;
pub use ic::Instruction;
pub use ic::IntermediateCode;
pub use identifier::BoundedString;
pub use table::Table;
pub use value::Value;
pub use vm::VirtualMachine;

Modulesยง

codegen
Intermediate code generation from the AST.
column
Columns in a table.
database
Databases.
expr
SQL expressions and their evaluation.
ic
Intermediate representation (IR) and instruction set for an SQL database.
identifier
Names used for tables, columns, schemas, DBs, etc.
parser
SQL parsing. A thin wrapper around sqlparser.
schema
Schemas (as in a namespace for tables, not a database schema).
table
Tables and rows.
value
Values contained in a table cell, its operations and errors.
vm
The executor virtual machine, its registers and errors.