dirsql 0.3.31 → 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.
- package/README.md +71 -15
- package/package.json +13 -12
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `dirsql` (TypeScript SDK)
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
|
@@ -9,32 +9,88 @@ Also available as [`dirsql` on crates.io](https://crates.io/crates/dirsql) and [
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
|
|
12
|
+
npm add dirsql
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Prebuilt binaries ship for linux-x64, linux-arm64, darwin-x64, darwin-arm64, and win32-x64
|
|
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
16
|
|
|
17
|
-
##
|
|
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
|
|
18
40
|
|
|
19
41
|
```typescript
|
|
20
42
|
import { readFileSync } from "node:fs";
|
|
21
|
-
import { DirSQL } from "dirsql";
|
|
43
|
+
import { DirSQL, type TableDef } from "dirsql";
|
|
22
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 });
|
|
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
|
|
23
71
|
const db = new DirSQL({
|
|
24
|
-
root: "
|
|
25
|
-
tables: [
|
|
26
|
-
|
|
27
|
-
ddl: "CREATE TABLE users (name TEXT, age INTEGER)",
|
|
28
|
-
glob: "data/*.json",
|
|
29
|
-
extract: (filePath) => JSON.parse(readFileSync(filePath, "utf8")),
|
|
30
|
-
},
|
|
31
|
-
],
|
|
72
|
+
root: "./my-blog",
|
|
73
|
+
tables: [/* ... */],
|
|
74
|
+
ignore: ["**/drafts/**", "**/.git/**"],
|
|
32
75
|
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Watching for changes
|
|
33
79
|
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
}
|
|
36
86
|
```
|
|
37
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
|
+
|
|
38
94
|
## License
|
|
39
95
|
|
|
40
96
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dirsql",
|
|
3
|
-
"version": "0.3.
|
|
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",
|
|
@@ -178,7 +178,8 @@
|
|
|
178
178
|
"devDependencies": {
|
|
179
179
|
"@biomejs/biome": "^1.9.0",
|
|
180
180
|
"@napi-rs/cli": "^3.0.0",
|
|
181
|
-
"@
|
|
181
|
+
"@tsconfig/node20": "^20.1.9",
|
|
182
|
+
"@types/node": "^20.19.43",
|
|
182
183
|
"@types/sql.js": "^1.4.11",
|
|
183
184
|
"@vitest/coverage-v8": "^3.1.1",
|
|
184
185
|
"sql.js": "^1.14.1",
|
|
@@ -197,15 +198,15 @@
|
|
|
197
198
|
"smol-toml": "^1.6.1"
|
|
198
199
|
},
|
|
199
200
|
"optionalDependencies": {
|
|
200
|
-
"@dirsql/lib-linux-x64-gnu": "0.3.
|
|
201
|
-
"@dirsql/lib-linux-arm64-gnu": "0.3.
|
|
202
|
-
"@dirsql/lib-darwin-x64": "0.3.
|
|
203
|
-
"@dirsql/lib-darwin-arm64": "0.3.
|
|
204
|
-
"@dirsql/lib-win32-x64-msvc": "0.3.
|
|
205
|
-
"@dirsql/cli-linux-x64-gnu": "0.3.
|
|
206
|
-
"@dirsql/cli-linux-arm64-gnu": "0.3.
|
|
207
|
-
"@dirsql/cli-darwin-x64": "0.3.
|
|
208
|
-
"@dirsql/cli-darwin-arm64": "0.3.
|
|
209
|
-
"@dirsql/cli-win32-x64-msvc": "0.3.
|
|
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"
|
|
210
211
|
}
|
|
211
212
|
}
|