Skip to content

ryanhossain9797/gluesql

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GlueSQL

crates.io docs.rs LICENSE Rust

SQL Database Engine as a Library

GlueSQL is a SQL database library written in Rust which provides parser (sqlparser-rs), execution layer, and an optional storage (sled).
Developers can use GlueSQL to build their own SQL databases or they can simply use GlueSQL as an embedded SQL database using default storage.

Standalone Mode

You can simply use GlueSQL as an embedded SQL database, GlueSQL provides sled as a default storage engine.

Installation

In your Cargo.toml

[dependencies]
gluesql = { version = "0.1.15", features = ["sled-storage"] }

Usage

use gluesql::{parse, Glue, SledStorage};

fn main() {
    let storage = SledStorage::new("data.db").unwrap();
    let mut glue = Glue::new(storage);

    let sqls = "
        CREATE TABLE Glue (id INTEGER);
        INSERT INTO Glue VALUES (100);
        INSERT INTO Glue VALUES (200);
        SELECT * FROM Glue WHERE id > 100;
        DROP TABLE Glue;
    ";
    
    for query in parse(sqls).unwrap() {
        glue.execute(&query).unwrap();
    }
}

SQL Library Mode (For Custom Storage)

Installation

Now you don't need to include sled-storage. So in Cargo.toml,

[dependencies]
gluesql = "0.1.15"

Usage

All you only need to do is implementing 2 traits: Store and StoreMut! In src/store.rs,

pub trait Store<T: Debug> {
    fn fetch_schema(&self, table_name: &str) -> Result<Schema>;
    fn scan_data(&self, table_name: &str) -> Result<RowIter<T>>;
}

pub trait StoreMut<T: Debug> where Self: Sized {
    fn generate_id(self, table_name: &str) -> MutResult<Self, T>;
    fn insert_schema(self, schema: &Schema) -> MutResult<Self, ()>;
    fn delete_schema(self, table_name: &str) -> MutResult<Self, ()>;
    fn insert_data(self, key: &T, row: Row) -> MutResult<Self, Row>;
    fn delete_data(self, key: &T) -> MutResult<Self, ()>;
}

Examples - GlueSQL-js

Use SQL in web browsers!
GlueSQL-js provides 3 storage options,

  • in-memory
  • localStorage
  • sessionStorage.

SQL Features

GlueSQL currently supports limited queries, it's in very early stage.

  • CREATE with 4 types: INTEGER, FLOAT, BOOLEAN, TEXT with an optional NULL attribute.
  • INSERT, UPDATE, DELETE, SELECT, DROP TABLE
  • Nested select, join, aggregations ...

You can see current query supports in src/tests/*.

Other expected use cases

  • Run SQL in web browsers - gluesql-js It would be cool to make state management library using gluesql-js.
  • Add SQL layer to NoSQL databases: Redis, CouchDB...
  • Build new SQL database management system

Contribution

It's very early stage, please feel free to do whatever you want to.
Only the thing you need to be aware of is...

  • Except for src/glue.rs and src/tests/, there is no place to use mut keyword.

About

GlueSQL is quite sticky, it attaches to anywhere.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%