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

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