Crate kite_sql

Source
Expand description

KiteSQL is a high-performance SQL database that can be embedded in Rust code (based on RocksDB by default), making it possible to call SQL just like calling a function. It supports most of the syntax of SQL 2016.

KiteSQL provides thread-safe API: DataBase::run for running SQL

KiteSQL uses DataBaseBuilder for instance construction, configuration in builder mode

Support type

  • SqlNull
  • Boolean
  • Tinyint
  • UTinyint
  • Smallint
  • USmallint
  • Integer
  • UInteger
  • Bigint
  • UBigint
  • Float
  • Double
  • Char
  • Varchar
  • Date
  • DateTime
  • Time
  • Tuple

support optimistic transaction with the Database::new_transaction method.

support UDF (User-Defined Function) so that users can customize internal calculation functions with the DataBaseBuilder::register_function

§Examples

use kite_sql::db::{DataBaseBuilder, ResultIter};
use kite_sql::errors::DatabaseError;
use kite_sql::implement_from_tuple;
use kite_sql::types::value::DataValue;

#[derive(Default, Debug, PartialEq)]
struct MyStruct {
    pub c1: i32,
    pub c2: String,
}

implement_from_tuple!(
    MyStruct, (
        c1: i32 => |inner: &mut MyStruct, value| {
            if let DataValue::Int32(Some(val)) = value {
                inner.c1 = val;
            }
        },
        c2: String => |inner: &mut MyStruct, value| {
            if let DataValue::Utf8 { value: Some(val), .. } = value {
                inner.c2 = val;
            }
        }
    )
);

#[cfg(feature = "macros")]
fn main() -> Result<(), DatabaseError> {
    let database = DataBaseBuilder::path("./hello_world").build()?;

    database
        .run("create table if not exists my_struct (c1 int primary key, c2 int)")?
        .done()?;
    database
        .run("insert into my_struct values(0, 0), (1, 1)")?
        .done()?;

    let iter = database.run("select * from my_struct")?;
    let schema = iter.schema().clone();

    for tuple in iter {
        println!("{:?}", MyStruct::from((&schema, tuple?)));
    }
    database.run("drop table my_struct")?.done()?;

    Ok(())
}

Modules§

binder
catalog
db
errors
execution
expression
macros
parser
planner
serdes
storage
types

Macros§

implement_from_tuple
Examples
implement_num_serialization
implement_ptr_serialization
implement_serialization_by_bincode
numeric_binary_evaluator_definition
numeric_unary_evaluator_definition
scala_function
Examples
single_mapping
table_function
Examples
throw