Crate gluesql

source · []
Expand description


gluesql is a SQL database library written in Rust.
It provides a parser (sqlparser-rs), execution layer, and optional storages (sled or memory) packaged into a single library.
Developers can choose to use GlueSQL to build their own SQL database, or as an embedded SQL database using the default storage engine.


#[cfg(feature = "sled-storage")]
fn main() {
    use gluesql::prelude::*;

    let storage = SledStorage::new("data/doc-db").unwrap();
    let mut glue = Glue::new(storage);
    let sqls = vec![
        "DROP TABLE IF EXISTS Glue;",
        "CREATE TABLE Glue (id INTEGER);",
        "INSERT INTO Glue VALUES (100);",
        "INSERT INTO Glue VALUES (200);",
        "SELECT * FROM Glue WHERE id > 100;",

    for sql in sqls {
        let output = glue.execute(sql).unwrap();
        println!("{:?}", output)

#[cfg(not(feature = "sled-storage"))]
fn main() {}

Custom Storage

To get started, all you need to implement for gluesql is implementing three traits (two for functions, one for running tests).
There are also optional traits. Whether to implement it or not is all up to you.

Store traits

Optional Store traits

Trait to run integration tests


gluesql provides integration tests as a module.
Developers who wants to make their own custom storages can import and run those tests.
/tests/ might look quite empty, but actual test cases exist in test-suite workspace.

Example code to see,

After you implement Tester trait, the only thing you need to do is calling generate_tests! macro.