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.
You can use GlueSQL as an embedded SQL database.
GlueSQL provides two reference storage options.
SledStorage
- Persistent storage engine based onsled
MemoryStorage
- Non-persistent storage engine based onBTreeMap
Cargo.toml
[dependencies]
gluesql = "0.11"
- CLI application
$ cargo install gluesql
use gluesql::prelude::*;
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)
}
}
sled-storage
and memory-storage
features are optional, so these are not required for custom storage makers.
[dependencies.gluesql]
version = "0.11"
default-features = false
features = ["alter-table", "index", "transaction", "metadata"]
alter-table
- ALTER TABLE query supportindex
- CREATE INDEX and DROP INDEX, index supporttransaction
- BEGIN, ROLLBACK and COMMIT, transaction supportmetadata
- SHOW TABLES and SHOW VERSION support
pub trait Store<T: Debug> {
async fn fetch_schema(..) -> ..;
async fn scan_data(..) -> ..;
}
pub trait StoreMut<T: Debug> where Self: Sized {
async fn insert_schema(..) -> ..;
async fn delete_schema(..) -> ..;
async fn insert_data(..) -> ..;
async fn update_data(..) -> ..;
async fn delete_data(..) -> ..;
}
pub trait AlterTable where Self: Sized {
async fn rename_schema(..) -> ..;
async fn rename_column(..) -> ..;
async fn add_column(..) -> ..;
async fn drop_column(..) -> ..;
}
pub trait Index<T: Debug> {
async fn scan_indexed_data(..) -> ..;
}
pub trait IndexMut<T: Debug> where Self: Sized {
async fn create_index(..) -> ..;
async fn drop_index(..) -> ..;
}
pub trait Transaction where Self: Sized {
async fn begin(..) -> ..;
async fn rollback(..) -> ..;
async fn commit(..) -> ..;
}
pub trait Metadata {
fn version(..) -> String;
async fn schema_names(..) -> ..;
}
GlueSQL.js is a SQL database for web browsers and Node.js. It works as an embedded database and entirely runs in the browser. GlueSQL.js supports in-memory storage backend, but it will soon to have localStorage, sessionStorage and indexedDB backend supports.
GlueSQL currently supports a limited subset of queries. It's being actively developed.
- Numeric
INT(8)
,INT(16)
,INT(32)
,INT(64)
,INT(128)
,INTEGER
,FLOAT
,DECIMAL
- Date
DATE
,TIMESTAMP
,TIME
INTERVAL
BOOLEAN
,TEXT
,UUID
,MAP
,LIST
CREATE TABLE
,DROP TABLE
ALTER TABLE
-ADD COLUMN
,DROP COLUMN
,RENAME COLUMN
andRENAME TO
.CREATE INDEX
,DROP INDEX
INSERT
,UPDATE
,DELETE
,SELECT
GROUP BY
,HAVING
ORDER BY
- Transaction queries:
BEGIN
,ROLLBACK
andCOMMIT
- Nested select, join, aggregations ...
You can see tests for the currently supported queries in test-suite/src/*.
There are a few simple rules to follow.
- No
mut
keywords in thecore
workspace (exceptglue.rs
). - Every error must have corresponding integration test cases to generate.
(except forUnreachable-
andConflict-
error types)