Skip to content

gluesql/gluesql-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gluesql-js has been moved to the GlueSQL main repo

Link

https://github.com/gluesql/gluesql/tree/main/gluesql-js


GlueSQL-js

npm version License

Use SQL in web browsers!

GlueSQL-js provides 3 storage options

  • In-memory
  • LocalStorage
  • SessionStorage

📦 Installation

npm install gluesql

☁️ Usage

const gluesql = import('gluesql');

async function main() {
  const { Glue } = await gluesql;
  const db = new Glue("memory");
  /* other options:
    const db = new Glue("localstorage", "{db-name}");
    const db = new Glue("sessionstorage", "{db-name}");
  */
  
  const sql = `
    CREATE TABLE Test (id INTEGER, name TEXT);
    INSERT INTO Test VALUES (101, "Glue");
    INSERT INTO Test VALUES (102, "Rust");
    INSERT INTO Test VALUES (103, "Yeah");
  `;
  
  await db.execute(sql);

  const items = (await db.execute("SELECT * FROM Test WHERE id < 103;"))[0];
  /* items:
    [
      [101, "Glue"],
      [102, "Rust"],
    ] 
  */
}

✨ Examples

📚 Features

📗 Supported Queries

  • CREATE TABLE
  • ALTER TABLE
  • INSERT
  • UPDATE
  • SELECT
  • DELETE
  • DROP TABLE

📘 Supported Data Types & Attributes

Types

  • INTEGER
  • FLOAT
  • BOOLEAN
  • TEXT

Attributes

  • NULL | NOT NULL

Example

CREATE TABLE User (
  id INTEGER,
  name TEXT NULL,
  valid BOOLEAN
);

📙 Supported SQL Syntax Keywords

Join (only with ON keyword)

  • INNER JOIN | JOIN
  • LEFT JOIN | LEFT OUTER JOIN

Example

SELECT * FROM TableA
JOIN TableB ON TableB.a_id = TableA.id
WHERE TableA.id > 10;

NestedSelect

Example

SELECT * FROM User
WHERE User.id IN (SELECT id IN Other);

Aggregation

  • COUNT
  • MAX
  • MIN
  • SUM
  • GROUP BY, HAVING

Example

SELECT
  COUNT(*),
  MAX(amount) + MIN(amount),
  SUM(amount)
FROM TableA
GROUP BY city
HAVING COUNT(*) > 10;