Crate steeldb

Source
Expand description

SteelDB Crate

§Introduction

SteelDB is a Database created for learning purposes.

The goal is to implement a Database from scratch in Rust, and document the process along the way.

The main reference is SQLite architecture. However, SteelDB will differ significantly in certain areas.

Currently, SteelDB can only be used in an embedded manner, but will eventually also support a server-client architecture.

There are two main ways of using it:

  1. Using the SteelDB struct for a programmatic experience.
  2. Using the Repl struct for an interactive experience.

Note that the current version is extremely limited, as it only supports the SELECT clause.

§Examples

§Database API

use steeldb::{SteelDB, ExecutionResult};

let mut database = SteelDB::new();
let result = database.execute("select name".to_string());
match result {
    ExecutionResult::TableResult(table) => {
        println!("{:?}", table);
    }
    ExecutionResult::VoidOK => println!("Command OK"),
    ExecutionResult::ParseError(error) => println!("Parse error: {:?}", error),
    ExecutionResult::CommandError(error) => println!("Command error: {:?}", error),
}

§REPL

To use the REPL, one can simply install SteelDB and execute cargo run. Effectively, this is the same as:

use steeldb::Repl;

fn main() {
    let mut repl = Repl::new();
    repl.main_loop();
}

When the shell starts, one provides input which will be fed into the execute function of the SteelDB struct. The REPL automatically handles pretty printing tables and printing errors back to the standard output.

Modules§

config
The database config. For now, everything is hardcoded.

Structs§

Repl
The main struct that is publicly exposed by this module Repl. See example in the root crate on how to use it.
SteelDB
The main struct exposed by the crate. See the crate root documentation on how to use it.
Table
This defines a way to keep the data in-memory by the SteelDB. It also represents the Table that the user receives back when querying the database. This is currently in a columnar format. Most of the exposed functionality here is a low level API meant to be used during the database development. It is not meant to be used directly by database users.

Enums§

DataType
The supported data type stored by the Database. By using the Enum, we can resolve the column type dynamically in run time.
ExecutionResult
The return type given by the SteelDB::execute function.

Constants§

VERSION
Crate version defined in Cargo.toml file, retrieved at runtime. This is displayed in the REPL.