basaltdb 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Maniarasan Sivaseran and Basalt contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,116 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/basalt-db/basalt/main/docs/basalt-icon.png" alt="Basalt" width="96" height="96">
3
+ </p>
4
+
5
+ # basaltdb — JavaScript/TypeScript client for Basalt
6
+
7
+ Use [Basalt](https://github.com/basalt-db/basalt) from Node or the
8
+ browser. Two modes, one API:
9
+
10
+ - **Embedded** (in-process, WebAssembly — like `sql.js`): the whole engine runs
11
+ in your process, no server. The database lives in memory. Great for tests,
12
+ demos, notebooks, and browser apps.
13
+ - **Client/server**: talk to a running `basalt` server over HTTP for a
14
+ persistent, disk-backed database.
15
+
16
+ The WASM binary is bundled **inside** the package (single file, base64-embedded),
17
+ so there are no extra assets to host or `fetch` — it just works in Node and
18
+ bundlers.
19
+
20
+ ```bash
21
+ npm install basaltdb
22
+ ```
23
+
24
+ ## Embedded (in-process)
25
+
26
+ ```js
27
+ import { Basalt } from 'basaltdb';
28
+
29
+ const db = await Basalt.create(); // in-memory, seeded with a demo dataset
30
+ db.exec('CREATE TABLE t (id BIGINT PRIMARY KEY, name VARCHAR, qty INT)');
31
+ db.exec("INSERT INTO t (id, name, qty) VALUES (1, 'widget', 5)");
32
+
33
+ db.query('SELECT * FROM t'); // -> [{ id: 1, name: 'widget', qty: 5 }]
34
+ const r = db.exec('SELECT COUNT(*) AS c FROM t');
35
+ console.log(r.stats.ms, r.stats.access); // timing + access method
36
+ ```
37
+
38
+ `exec()` returns the full result object: `{ columns, types, rows, total_rows,
39
+ truncated, stats, plan, message? }`, plus `.toObjects()`. `query()` is shorthand
40
+ for `exec(sql).toObjects()`.
41
+
42
+ ## Client/server (HTTP)
43
+
44
+ ```js
45
+ import { BasaltClient } from 'basaltdb';
46
+
47
+ const db = new BasaltClient('http://127.0.0.1:8090', { db: 'mydb' });
48
+ await db.query('SELECT * FROM users ORDER BY id');
49
+ await db.databases(); // list served databases
50
+ await db.schema(); // tables + columns
51
+ ```
52
+
53
+ In Node < 18 (no global `fetch`) pass one: `new BasaltClient(url, { fetch })`.
54
+
55
+ ## Query builder (ORM-lite)
56
+
57
+ A small fluent builder that generates SQL. It works the same on both `Basalt`
58
+ (sync) and `BasaltClient` (async) — `await` works in both cases:
59
+
60
+ ```js
61
+ await db.table('users').select('id', 'name').where('tier', '>', 1).orderBy('id', 'DESC').all();
62
+ await db.table('users').where('id', 1).first();
63
+ db.table('users').insert({ id: 4, name: 'dana', tier: 2 });
64
+ db.table('users').insert([{ id: 5, name: 'e' }, { id: 6, name: 'f' }]);
65
+ db.table('users').where('id', 6).update({ tier: 3 });
66
+ db.table('users').where('id', 6).delete();
67
+ ```
68
+
69
+ Values are escaped (`lit()`); **identifiers are never taken from user input**.
70
+ Call `.toSQL()` on any builder to see the generated statement.
71
+
72
+ ## What Basalt supports (and doesn't, yet)
73
+
74
+ This is a young, learning-oriented engine — the builder deliberately stays close
75
+ to what the SQL engine actually does:
76
+
77
+ - ✅ `SELECT` with `WHERE` / `GROUP BY` / aggregates / `ORDER BY` / `LIMIT`,
78
+ `INNER`/`LEFT JOIN`, `INSERT` (positional or column-list), `UPDATE`, `DELETE`,
79
+ `CREATE/DROP TABLE`, `CREATE/DROP INDEX`.
80
+ - ⛔ No transactions, no subqueries/CTEs/window functions, no prepared
81
+ statements yet (see the [roadmap](https://github.com/basalt-db/basalt/blob/main/ROADMAP.md)).
82
+ That's why this is a query builder rather than a full ORM adapter — a Prisma /
83
+ Sequelize / Drizzle dialect will land once transactions and richer SQL do.
84
+
85
+ ## API
86
+
87
+ - `Basalt.create()` → `Promise<Basalt>` — embedded in-memory engine.
88
+ - `db.exec(sql)` → `Result` · `db.query(sql)` → `object[]` · `db.schema()` → tables.
89
+ - `new BasaltClient(url, { db, fetch })` — async `exec` / `query` / `databases` /
90
+ `schema` / `createDatabase` / `dropDatabase` / `use(db)`.
91
+ - `db.table(name)` → builder: `select`, `where`, `orderBy`, `limit`, `all`,
92
+ `first`, `insert`, `update`, `delete`, `toSQL`.
93
+ - `lit(value)` — SQL literal formatting; `BasaltError` — thrown on engine errors.
94
+
95
+ ## Building `src/engine.js`
96
+
97
+ `src/engine.js` is the Basalt C++ engine compiled to a single-file ESM WebAssembly
98
+ bundle (base64-embedded), vendored here so `npm install` needs no toolchain. It's
99
+ generated from the engine sources in the **[main Basalt repo](https://github.com/basalt-db/basalt)**
100
+ (`src/`) with emscripten:
101
+
102
+ ```bash
103
+ # in a checkout of basalt-db/basalt
104
+ emcc -std=c++17 -O3 -fexceptions -I src \
105
+ src/logical.cpp src/storage.cpp src/sql.cpp src/exec.cpp \
106
+ src/exec_join.cpp src/database.cpp src/wasm.cpp \
107
+ -sMODULARIZE=1 -sEXPORT_ES6=1 -sSINGLE_FILE=1 -sENVIRONMENT=web,node \
108
+ -sEXPORT_NAME=createBasalt -sEXPORTED_RUNTIME_METHODS=ccall,cwrap \
109
+ -sEXPORTED_FUNCTIONS=_hydb_exec,_hydb_schema,_hydb_init,_malloc,_free \
110
+ -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=64MB -o engine.js
111
+ # then copy engine.js -> this repo's src/engine.js
112
+ ```
113
+
114
+ Run the smoke test (embedded engine, no server): `npm test`.
115
+
116
+ MIT. Part of the [Basalt](https://github.com/basalt-db/basalt) project.
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "basaltdb",
3
+ "version": "0.1.0",
4
+ "description": "Official JavaScript/TypeScript client for Basalt — a from-scratch HTAP database engine. Run it embedded in-process via WebAssembly (Node & browser), or talk to a Basalt server over HTTP.",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "module": "./src/index.js",
8
+ "types": "./src/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./src/index.d.ts",
12
+ "import": "./src/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "src/index.js",
17
+ "src/index.d.ts",
18
+ "src/engine.js",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "test": "node test/smoke.mjs",
23
+ "prepublishOnly": "npm test"
24
+ },
25
+ "keywords": [
26
+ "database", "sql", "htap", "olap", "oltp", "columnar", "wasm",
27
+ "webassembly", "embedded-database", "basalt", "in-memory", "analytics"
28
+ ],
29
+ "homepage": "https://github.com/basalt-db/basalt-js",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/basalt-db/basalt-js.git"
33
+ },
34
+ "bugs": { "url": "https://github.com/basalt-db/basalt-js/issues" },
35
+ "license": "MIT",
36
+ "engines": { "node": ">=18" },
37
+ "sideEffects": false
38
+ }