GithubHelp home page GithubHelp logo

yugeeklab / gluesql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gluesql/gluesql

0.0 0.0 0.0 2.45 MB

GlueSQL is quite sticky. It attaches to anywhere.

License: Apache License 2.0

JavaScript 0.19% Rust 99.68% HTML 0.13%

gluesql's Introduction

GlueSQL

crates.io npm LICENSE Rust docs.rs Chat Coverage Status

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 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.

Standalone Mode

You can use GlueSQL as an embedded SQL database.
GlueSQL provides three reference storage options.

  • SledStorage - Persistent storage engine based on sled
  • MemoryStorage - Non-persistent storage engine based on BTreeMap
  • SharedMemoryStorage - Non-persistent storage engine which works in multi-threaded environment

Installation

  • Cargo.toml
[dependencies]
gluesql = "0.13"
  • Install CLI
$ cargo install gluesql
  • Run CLI
$ gluesql [--path ~/data_path] [--execute ~/sql_path]

Migration using CLI

Dump whole schemas and data by generating SQL using --dump {PATH} option

$ gluesql --path ~/glue_data --dump ./dump.sql
-- dump.sql
CREATE TABLE User (id INT, name TEXT);
CREATE INDEX User_id ON User (id);
..
INSERT INTO User VALUES (1, 'Foo'), (2, 'Bar') ..
..

Import database

$ gluesql --path ~/new_data --execute ./dump.sql

Usage

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)
    }
}

SQL Library Mode (For Custom Storage)

Installation

sled-storage and memory-storage features are optional, so these are not required for custom storage makers.

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

Four features below are also optional

  • alter-table - ALTER TABLE query support
  • index - CREATE INDEX and DROP INDEX, index support
  • transaction - BEGIN, ROLLBACK and COMMIT, transaction support

Usage

Two mandatory store traits to implement

pub trait Store {
    async fn fetch_schema(..) -> ..;
    async fn fetch_data(..) -> ..;
    async fn scan_data(..) -> ..;
}

pub trait StoreMut where Self: Sized {
    async fn insert_schema(..) -> ..;
    async fn delete_schema(..) -> ..;
    async fn append_data(..) -> ..;
    async fn insert_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 {
    async fn scan_indexed_data(..) -> ..;
}

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

GlueSQL.js

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.

More info

SQL Features

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

Data Types

Category Type
Numeric INT8, INT16, INT32, INTEGER, INT128, UINT8, FLOAT, DECIMAL
Date DATE, TIME, TIMESTAMP, INTERVAL
Others BOOLEAN, TEXT, UUID, MAP, LIST, BYTEA

Queries

  • CREATE TABLE, DROP TABLE
  • ALTER TABLE - ADD COLUMN, DROP COLUMN, RENAME COLUMN and RENAME TO.
  • CREATE INDEX, DROP INDEX
  • INSERT, UPDATE, DELETE, SELECT
  • 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 test-suite/src/*.

gluesql's People

Contributors

panarch avatar ever0de avatar devgony avatar zmrdltl avatar bearney74 avatar seonghun-dev avatar mrgravity817 avatar chobobdev avatar ryanhossain9797 avatar yugeeklab avatar ceojinsung avatar ding-young avatar kygost avatar yjh0502 avatar 24seconds avatar kim-seo-hyun avatar sa1 avatar boomkim avatar maruoovv avatar pythonbrad avatar bugoverdose avatar woojinnn avatar devil-k avatar silathdiir avatar redblueflame avatar vbbono avatar noproto avatar simple6192 avatar heka1024 avatar yujonglee avatar

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.