sekejap 0.13.3 → 0.14.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/README.md CHANGED
@@ -1,62 +1,86 @@
1
- # sekejap for Node.js
1
+ # sekejap
2
2
 
3
- **Status: working** (tested). Native Node.js binding via [napi-rs](https://napi.rs/) —
4
- `#[napi]` over `sekejap::CoreDB`, compiled to a native N-API addon.
3
+ Embedded **graph-first, multi-model database** for Node.js — SQL + graph + vector +
4
+ spatial in one native library. No server, no external process; the whole engine runs
5
+ in-process on a Rust core.
5
6
 
6
- ## Run it
7
+ - **PostgreSQL-like SQL** — `CREATE TABLE`, `INSERT`, `SELECT … WHERE`, parameters (`$1`).
8
+ - **Graph** — link records and traverse relationships.
9
+ - **Prepared statements** — compile once, run many with varying parameters.
10
+ - **No native build** — the prebuilt binaries for every platform ship inside the
11
+ package. No Rust toolchain, no `node-gyp`, no compile step.
7
12
 
8
- ```bash
9
- cd wrappers/node
10
- cargo build --release # builds the addon
11
- cp target/release/libsekejap_node.dylib sekejap.node # (.so on Linux, .dll on Windows)
12
- node test.cjs # → OK — sekejap-node 0.13.0 …
13
+ ## Install
14
+
15
+ ```sh
16
+ npm install sekejap
13
17
  ```
14
18
 
15
- For real packaging use `npx @napi-rs/cli build --release`, which names the addon
16
- per-platform and generates `index.js` + `index.d.ts` (TypeScript types). JS API:
17
- `Db.open(path)`, `execute`, `query`/`queryParams` (→ JSON string, `JSON.parse` it),
18
- `put`, `link`, `nodeCount`/`edgeCount`, `compact`, `version()`.
19
+ Works on macOS (arm64/x64), Linux (x64/arm64), and Windows (x64), Node ≥ 16.
19
20
 
20
- ## Approach
21
+ ## Quick start
21
22
 
22
- napi-rs is Node's equivalent of PyO3: you annotate Rust with `#[napi]` and it
23
- builds a native Node addon (`.node`) that speaks Node's stable **N-API** directly —
24
- idiomatic JS types, no manual C ABI. (An alternative is `koffi`/`ffi-napi` calling
25
- the C ABI in `../c`, but napi-rs gives better perf and TypeScript types.)
23
+ ```js
24
+ const { Db, version } = require('sekejap');
26
25
 
26
+ const db = Db.open('/tmp/notes'); // open (or create) a database directory
27
+
28
+ // Define a table and insert rows with SQL.
29
+ db.execute('CREATE TABLE note (_key TEXT PRIMARY KEY, title TEXT, pinned INTEGER)');
30
+ db.execute("INSERT INTO note (_key, title, pinned) VALUES ('n1', 'Buy milk', 1)");
31
+
32
+ // Insert a record directly (no SQL) as a JSON payload.
33
+ db.put('note/n2', JSON.stringify({ _collection: 'note', _key: 'n2', title: 'Call Sam', pinned: 0 }));
34
+
35
+ // Query. Results come back as a JSON string — JSON.parse it.
36
+ const notes = JSON.parse(db.query('SELECT * FROM note'));
37
+ console.log(notes);
38
+ // [ { _key: 'n1', title: 'Buy milk', pinned: 1, ... }, { _key: 'n2', ... } ]
39
+
40
+ // Parameterized query ($1, $2, …) — injection-safe. Params are a JSON array string.
41
+ const pinned = JSON.parse(db.queryParams('SELECT title FROM note WHERE pinned = $1', JSON.stringify([1])));
42
+
43
+ // Prepared statement — compile once, run many.
44
+ const byPin = db.prepare('SELECT _key FROM note WHERE pinned = $1');
45
+ for (const p of [0, 1]) {
46
+ console.log(JSON.parse(db.queryPrepared(byPin, JSON.stringify([p]))));
47
+ }
48
+
49
+ // Graph: link two records.
50
+ db.link('note/n1', 'note/n2', 'related');
51
+ console.log('nodes:', db.nodeCount(), 'edges:', db.edgeCount());
52
+
53
+ // Flush + compact to disk after heavy writes.
54
+ db.compact();
27
55
  ```
28
- wrappers/node/
29
- ├── Cargo.toml # crate-type = ["cdylib"], deps: napi, napi-derive; depends on the sekejap crate
30
- ├── package.json # name "sekejap", @napi-rs/cli build/publish scripts
31
- ├── src/lib.rs # #[napi] wrappers over sekejap::CoreDB / Engine
32
- ├── index.d.ts # generated TypeScript types
33
- └── examples/ # .js / .ts usage
34
- ```
35
56
 
36
- Minimal `Cargo.toml` to add (then add `wrappers/node` to the workspace members):
57
+ ## API
58
+
59
+ | Method | Purpose |
60
+ |---|---|
61
+ | `Db.open(path)` | Open (or create) a database at a directory path |
62
+ | `db.execute(sql)` | Run DDL/DML (`CREATE`/`INSERT`/`UPDATE`/`DELETE`) → rows affected |
63
+ | `db.query(sql)` | Run a `SELECT`/graph query → **JSON string** |
64
+ | `db.queryParams(sql, paramsJson)` | Parameterized query; `paramsJson` is a JSON array string |
65
+ | `db.prepare(sql)` / `db.queryPrepared(stmt, paramsJson)` | Prepared statements |
66
+ | `db.put(slug, payloadJson)` | Insert/replace one record by slug with a JSON payload |
67
+ | `db.link(from, to, edgeType)` | Create a graph edge |
68
+ | `db.nodeCount()` / `db.edgeCount()` | Counts |
69
+ | `db.compact()` | Flush WAL, rewrite payloads, reclaim RAM |
70
+ | `version()` | Library version |
37
71
 
38
- ```toml
39
- [package]
40
- name = "sekejap-node"
41
- version.workspace = true
42
- edition.workspace = true
72
+ `query` / `queryParams` / `queryPrepared` return a **JSON string** — decode with
73
+ `JSON.parse(...)`. It's an array of row objects.
43
74
 
44
- [lib]
45
- crate-type = ["cdylib"]
75
+ ### TypeScript
46
76
 
47
- [dependencies]
48
- sekejap = { path = "../.." }
49
- napi = { version = "2", features = ["napi8"] }
50
- napi-derive = "2"
77
+ Types ship with the package (`index.d.ts`) — no `@types` needed.
51
78
 
52
- [build-dependencies]
53
- napi-build = "2"
79
+ ```ts
80
+ import { Db } from 'sekejap';
81
+ const db = Db.open('/tmp/notes');
54
82
  ```
55
83
 
56
- ## Distribution
84
+ ## License
57
85
 
58
- - **Registry:** [npm](https://npmjs.com) → `npm install sekejap`
59
- - **Publish:** `npm publish`. Build prebuilt binaries per platform in CI with
60
- `@napi-rs/cli` (`napi build --release`) and ship them as platform packages under
61
- `optionalDependencies`, so users don't need a Rust toolchain.
62
- - Reserve the name `sekejap` on npm now.
86
+ Dual-licensed under **MIT OR Apache-2.0**.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sekejap",
3
- "version": "0.13.3",
3
+ "version": "0.14.0",
4
4
  "description": "Embedded graph-first multi-model database — Node.js binding",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "repository": "github:sekejapdb/sekejap",
Binary file
Binary file
Binary file
Binary file
Binary file