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.
You can use GlueSQL as an embedded SQL database. GlueSQL provides sled as a default storage engine.
In your Cargo.toml
:
toml
[dependencies]
gluesql = "0.5"
```rust 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();
}
} ```
sled-storage
is optional. So in Cargo.toml
:
```toml
[dependencies]
gluesql = { version = "0.5", default-features = false, features = ["alter-table"] }
gluesql = { version = "0.5", default-features = false } ```
There are two required 2 traits for using GlueSQL: Store
and StoreMut
.
In src/store/mod.rs
,
```rust
pub trait Store
pub trait StoreMut
.. there is also a single, optional trait:
In src/store/alter_table.rs
,
rust
pub trait AlterTable where Self: Sized {
async fn rename_schema(..) -> ..;
async fn rename_column(..) -> ..;
async fn add_column(..) -> ..;
async fn drop_column(..) -> ..;
}
Use SQL in web browsers! GlueSQL-js provides 3 storage options, * in-memory * localStorage * sessionStorage.
GlueSQL currently supports a limited subset of queries. It's being actively developed.
CREATE
with 4 types: INTEGER
, FLOAT
, BOOLEAN
, TEXT
with an optional NULL
attribute.ALTER TABLE
with 4 operations: ADD COLUMN
, DROP COLUMN
, RENAME COLUMN
and RENAME TO
.INSERT
, UPDATE
, DELETE
, SELECT
, DROP TABLE
GROUP BY
, HAVING
You can see tests for the currently supported queries in src/tests/*.
gluesql-js
.GlueSQL is still in the very early stages of development. Please feel free to contribute however you'd like!
The only thing you need to be aware of is...
- Except for src/glue.rs
, src/tests/
and src/utils/
, using the mut
keyword is discouraged.