https://github.com/gluesql/gluesql/tree/main/gluesql-js
Use SQL in web browsers!
GlueSQL-js provides 3 storage options
- In-memory
- LocalStorage
- SessionStorage
npm install gluesql
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"],
]
*/
}
CREATE TABLE
ALTER TABLE
INSERT
UPDATE
SELECT
DELETE
DROP TABLE
INTEGER
FLOAT
BOOLEAN
TEXT
NULL
|NOT NULL
Example
CREATE TABLE User (
id INTEGER,
name TEXT NULL,
valid BOOLEAN
);
INNER JOIN
|JOIN
LEFT JOIN
|LEFT OUTER JOIN
Example
SELECT * FROM TableA
JOIN TableB ON TableB.a_id = TableA.id
WHERE TableA.id > 10;
Example
SELECT * FROM User
WHERE User.id IN (SELECT id IN Other);
COUNT
MAX
MIN
SUM
GROUP BY
,HAVING
Example
SELECT
COUNT(*),
MAX(amount) + MIN(amount),
SUM(amount)
FROM TableA
GROUP BY city
HAVING COUNT(*) > 10;