GlueSQL

crates.io docs.rs LICENSE Rust Chat

SQL Database Engine as a Library

GlueSQL is a SQL database library written in Rust. It provides a parser (sqlparser-rs), execution layer, and optional storage (sled) 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.

Standalone Mode

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

Installation

In your Cargo.toml:

toml [dependencies] gluesql = "0.8"

Usage

```rust use gluesql::*; fn main() { 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)
}

} ```

SQL Library Mode (For Custom Storage)

Installation

sled-storage is optional, so it is not required for custom storage makers.

toml [dependencies.gluesql] version = "0.8" default-features = false features = ["sorter", "alter-table", "index", "transaction"]

Three features below are also optional.

Usage

There are two required 2 traits for using GlueSQL: Store and StoreMut. In src/store/mod.rs,

```rust pub trait Store { async fn fetchschema(..) -> ..; async fn scandata(..) -> ..; }

pub trait StoreMut where Self: Sized { async fn insertschema(..) -> ..; async fn deleteschema(..) -> ..; async fn insertdata(..) -> ..; async fn updatedata(..) -> ..; async fn delete_data(..) -> ..; } ```

There is also optional store traits In src/store/alter_table.rs & src/store/index.rs

```rust pub trait AlterTable where Self: Sized { async fn renameschema(..) -> ..; async fn renamecolumn(..) -> ..; async fn addcolumn(..) -> ..; async fn dropcolumn(..) -> ..; }

pub trait Index { async fn scanindexeddata(..) -> ..; }

pub trait IndexMut where Self: Sized { async fn createindex(..) -> ..; async fn dropindex(..) -> ..; }

pub trait Transaction where Self: Sized { async fn begin(..) -> ..; async fn rollback(..) -> ..; async fn commit(..) -> ..; } ```

Use Cases

GlueSQL-js

https://github.com/gluesql/gluesql-js
Use SQL in web browsers! GlueSQL-js provides 3 storage options,

GlueSQL Sheets

https://sheets.gluesql.com
Turn Google Sheets into a SQL database!
It uses Google Sheets as a storage.
Data is stored and updated from Google Sheets.

Other expected use cases

SQL Features

GlueSQL currently supports a limited subset of queries. It's being actively developed.

You can see tests for the currently supported queries in src/tests/*.

Contribution

There are a few simple rules to follow.