GithubHelp home page GithubHelp logo

heej-ng / gluesql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gluesql/gluesql

0.0 0.0 0.0 1.08 MB

GlueSQL is quite sticky, it attaches to anywhere.

License: Apache License 2.0

Rust 100.00%

gluesql's Introduction

GlueSQL

crates.io docs.rs LICENSE Rust Chat codecov.io

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"]

Four features below are also optional.

  • sorter - ORDER BY support for non-indexed expressions.
  • alter-table - ALTER TABLE query support
  • index - CREATE INDEX & DROP INDEX, index support
  • transaction - BEGIN, ROLLBACK and COMMIT, transaction support

Usage

Two mandatory store traits to implement

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(..) -> ..;
}

Optional store traits

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

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

  • in-memory
  • localStorage
  • sessionStorage

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 and INTERVAL.
  • ALTER TABLE with 4 operations: ADD COLUMN, DROP COLUMN, RENAME COLUMN and RENAME TO.
  • CREATE INDEX, DROP INDEX
  • INSERT, UPDATE, DELETE, SELECT, DROP TABLE
  • GROUP BY, HAVING
  • ORDER BY
  • Transaction queries: BEGIN, ROLLBACK and COMMIT
  • 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 in src/executor and src/data.
  • Iterator should not be evaluated in the middle of execution layer.
  • Every error must have corresponding integration test cases to generate.
    (except for Unreachable- and Conflict- error types)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.