GitHub - gluesql/gluesql: GlueSQL is quite sticky, it attaches to anywhere.
source link: https://github.com/gluesql/gluesql
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
GlueSQL
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
:
[dependencies] gluesql = "0.8"
Usage
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.
[dependencies.gluesql] version = "0.8" default-features = false features = ["sorter", "alter-table", "index", "transaction"]
Three features below are also optional.
sorter
- ORDER BY support for non-indexed expressions.alter-table
- ALTER TABLE query supportindex
- CREATE INDEX & DROP INDEX, index supporttransaction
- BEGIN, ROLLBACK and COMMIT, transaction support
Usage
There are two required 2 traits for using GlueSQL: Store
and StoreMut
.
In src/store/mod.rs
,
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(..) -> ..; }
There is also optional store traits
In src/store/alter_table.rs
& src/store/index.rs
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(..) -> ..; }
Use Cases
GlueSQL-js
https://github.com/gluesql/gluesql-js
Use SQL in web browsers!
GlueSQL-js provides 3 storage options,
- in-memory
- localStorage
- sessionStorage
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
- Add SQL layer to NoSQL databases: Redis, CouchDB...
- Build new SQL database management system
SQL Features
GlueSQL currently supports a limited subset of queries. It's being actively developed.
CREATE TABLE
with 8 types:INTEGER
,FLOAT
,BOOLEAN
,TEXT
,DATE
,TIMESTAMP
,TIME
andINTERVAL
.ALTER TABLE
with 4 operations:ADD COLUMN
,DROP COLUMN
,RENAME COLUMN
andRENAME TO
.CREATE INDEX
,DROP INDEX
INSERT
,UPDATE
,DELETE
,SELECT
,DROP TABLE
GROUP BY
,HAVING
ORDER BY
- Transaction queries:
BEGIN
,ROLLBACK
andCOMMIT
- Nested select, join, aggregations ...
You can see tests for the currently supported queries in src/tests/*.
Contribution
There are a few simple rules to follow.
- No
mut
keywords insrc/executor
andsrc/data
. - Iterator should not be evaluated in the middle of execution layer.
- Every error must have corresponding integration test cases to generate.
(except forUnreachable-
andConflict-
error types)
Recommend
-
138
Sticky Sidebar Pure JavaScript plugin for making smart and high performance sticky sidebars. Basic Example
-
68
GitHub is where people build software. More than 27 million people use GitHub to discover, fork, and contribute to over 80 million projects.
-
42
org-sticky-header This package displays in the header-line the Org heading for the node that’s at the top of the window. This way, if the heading for the text at the top of the window is beyond the top of the window, you don’t...
-
6
React 17 attaches events to the root DOM container instead of the document node Jul 8, 2021 , by Archana Patil 4 minute read
-
8
topsy.el This library shows a sticky header at the top of the window. The header shows which definition the top line of the window is within. It’s intended as a simple alternative to semantic-stickyfunc-mode. It’s esp...
-
2
QOI - The “Quite OK Image” format for fast, lossless image compression Single-file MIT licensed library for C/C++ See qoi.h for the documentation. More in...
-
3
Colorful cooler for your cell — Razer’s RGB smartphone cooler attaches to iPhones with MagSafe Includes an adjustable fan and Peltier tile and works with iPhone and Android.
-
1
Redditor attaches ludicrous 30,000mAh battery to their Samsung Galaxy phone By Axel Metz pu...
-
3
This miniature chip is being used in a saliva-monitoring sensor that attaches to your tooth About the width of a #2 pencil lead By
-
1
This Prosthetic Limb Actually Attaches to the Wearer’s NervesA prosthetic arm that connects directly to the nervous system gives the user fine control over the motions of individual fingers—just by...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK