dirsql 0.3.32 → 0.3.33

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.
Files changed (2) hide show
  1. package/README.md +71 -13
  2. package/package.json +11 -11
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `dirsql` (TypeScript SDK)
2
2
 
3
- TypeScript SDK for `dirsql` -- napi-rs bindings wrapping the Rust core (`dirsql`).
3
+ Ephemeral SQL index over a local directory. `dirsql` watches a filesystem, ingests structured files into an in-memory SQLite database, and exposes a SQL query interface -- the filesystem is always the source of truth. Built on the Rust core via napi-rs bindings.
4
4
 
5
5
  [Documentation](https://thekevinscott.github.io/dirsql/?lang=typescript)
6
6
 
@@ -12,27 +12,85 @@ Also available as [`dirsql` on crates.io](https://crates.io/crates/dirsql) and [
12
12
  npm add dirsql
13
13
  ```
14
14
 
15
- ## Usage
15
+ Prebuilt binaries ship for linux-x64, linux-arm64, darwin-x64, darwin-arm64, and win32-x64; npm picks up the right one via `optionalDependencies`, so no Rust toolchain is required. The npm CLI requires **Node >= 20.11**.
16
+
17
+ ## Quick start
18
+
19
+ Constructing a `DirSQL` returns immediately; scanning runs in the background and every method awaits it, so you can query right away (or `await db.ready` to surface scan errors up front). Each table is a `(ddl, glob, extract)` object: the DDL defines the SQLite schema, the glob selects files (relative to `root`), and `extract` returns the rows a matched file contributes -- always an array, return `[]` to skip a file. `dirsql` does not read file contents; if `extract` needs the file body it reads `path` itself.
20
+
21
+ ```typescript
22
+ import { readFileSync } from "node:fs";
23
+ import { DirSQL, type TableDef } from "dirsql";
24
+
25
+ const tables: TableDef[] = [
26
+ {
27
+ ddl: "CREATE TABLE posts (title TEXT, author TEXT)",
28
+ glob: "posts/*.json",
29
+ extract: (path) => [JSON.parse(readFileSync(path, "utf8"))],
30
+ },
31
+ ];
32
+
33
+ const db = new DirSQL({ root: "./my-blog", tables });
34
+
35
+ const posts = await db.query("SELECT * FROM posts WHERE author = 'alice'");
36
+ console.log(posts);
37
+ ```
38
+
39
+ ## Multiple tables and joins
16
40
 
17
41
  ```typescript
18
42
  import { readFileSync } from "node:fs";
19
- import { DirSQL } from "dirsql";
43
+ import { DirSQL, type TableDef } from "dirsql";
44
+
45
+ const tables: TableDef[] = [
46
+ {
47
+ ddl: "CREATE TABLE posts (title TEXT, author_id TEXT)",
48
+ glob: "posts/*.json",
49
+ extract: (path) => [JSON.parse(readFileSync(path, "utf8"))],
50
+ },
51
+ {
52
+ ddl: "CREATE TABLE authors (id TEXT, name TEXT)",
53
+ glob: "authors/*.json",
54
+ extract: (path) => [JSON.parse(readFileSync(path, "utf8"))],
55
+ },
56
+ ];
57
+
58
+ const db = new DirSQL({ root: "./my-blog", tables });
20
59
 
60
+ const results = await db.query(`
61
+ SELECT posts.title, authors.name
62
+ FROM posts JOIN authors ON posts.author_id = authors.id
63
+ `);
64
+ ```
65
+
66
+ ## Ignoring files
67
+
68
+ Pass `ignore` patterns to skip files during scanning and watching:
69
+
70
+ ```typescript
21
71
  const db = new DirSQL({
22
- root: "/path/to/directory",
23
- tables: [
24
- {
25
- ddl: "CREATE TABLE users (name TEXT, age INTEGER)",
26
- glob: "data/*.json",
27
- extract: (filePath) => JSON.parse(readFileSync(filePath, "utf8")),
28
- },
29
- ],
72
+ root: "./my-blog",
73
+ tables: [/* ... */],
74
+ ignore: ["**/drafts/**", "**/.git/**"],
30
75
  });
76
+ ```
31
77
 
32
- const rows = await db.query("SELECT * FROM users WHERE age > 25");
33
- console.log(rows);
78
+ ## Watching for changes
79
+
80
+ `db.watch()` returns an async iterable of row-level change events as files change on disk:
81
+
82
+ ```typescript
83
+ for await (const event of db.watch()) {
84
+ console.log(`${event.action} on ${event.table}:`, event.row);
85
+ }
34
86
  ```
35
87
 
88
+ Each event has `.action` (`'insert'` | `'update'` | `'delete'` | `'error'`), `.table`, `.row` (the new row, or the deleted row on `delete`), `.oldRow` (the previous row, on `update`), `.filePath`, and `.error` (on `error`).
89
+
90
+ ## CLI
91
+
92
+ `npx dirsql` runs an HTTP server exposing the SDK over HTTP: `POST /query` for SQL and `GET /events` for a Server-Sent Events change stream. Requires **Node >= 20.11**. See the [CLI guide](https://thekevinscott.github.io/dirsql/cli/).
93
+
36
94
  ## License
37
95
 
38
96
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirsql",
3
- "version": "0.3.32",
3
+ "version": "0.3.33",
4
4
  "description": "Ephemeral SQL index over a local directory",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/thekevinscott/dirsql",
@@ -198,15 +198,15 @@
198
198
  "smol-toml": "^1.6.1"
199
199
  },
200
200
  "optionalDependencies": {
201
- "@dirsql/lib-linux-x64-gnu": "0.3.32",
202
- "@dirsql/lib-linux-arm64-gnu": "0.3.32",
203
- "@dirsql/lib-darwin-x64": "0.3.32",
204
- "@dirsql/lib-darwin-arm64": "0.3.32",
205
- "@dirsql/lib-win32-x64-msvc": "0.3.32",
206
- "@dirsql/cli-linux-x64-gnu": "0.3.32",
207
- "@dirsql/cli-linux-arm64-gnu": "0.3.32",
208
- "@dirsql/cli-darwin-x64": "0.3.32",
209
- "@dirsql/cli-darwin-arm64": "0.3.32",
210
- "@dirsql/cli-win32-x64-msvc": "0.3.32"
201
+ "@dirsql/lib-linux-x64-gnu": "0.3.33",
202
+ "@dirsql/lib-linux-arm64-gnu": "0.3.33",
203
+ "@dirsql/lib-darwin-x64": "0.3.33",
204
+ "@dirsql/lib-darwin-arm64": "0.3.33",
205
+ "@dirsql/lib-win32-x64-msvc": "0.3.33",
206
+ "@dirsql/cli-linux-x64-gnu": "0.3.33",
207
+ "@dirsql/cli-linux-arm64-gnu": "0.3.33",
208
+ "@dirsql/cli-darwin-x64": "0.3.33",
209
+ "@dirsql/cli-darwin-arm64": "0.3.33",
210
+ "@dirsql/cli-win32-x64-msvc": "0.3.33"
211
211
  }
212
212
  }