dirsql 0.3.4 → 0.3.6
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/dist/bin/dirsql.js +11 -9
- package/dist/bin/dirsql.js.map +1 -1
- package/docs/getting-started.md +2 -2
- package/docs/guide/querying.md +4 -0
- package/docs/guide/watching.md +4 -0
- package/package.json +27 -11
- package/dist/bin/die.test.d.ts +0 -2
- package/dist/bin/die.test.d.ts.map +0 -1
- package/dist/bin/die.test.js +0 -34
- package/dist/bin/die.test.js.map +0 -1
- package/dist/bin/main.test.d.ts +0 -2
- package/dist/bin/main.test.d.ts.map +0 -1
- package/dist/bin/main.test.js +0 -121
- package/dist/bin/main.test.js.map +0 -1
- package/dist/bin/resolveBinary.test.d.ts +0 -2
- package/dist/bin/resolveBinary.test.d.ts.map +0 -1
- package/dist/bin/resolveBinary.test.js +0 -60
- package/dist/bin/resolveBinary.test.js.map +0 -1
- package/docs/guide/cli.md +0 -131
- package/docs/guide/config.md +0 -193
- package/docs/guide/init.md +0 -84
package/dist/bin/dirsql.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// npm `bin` entry for `dirsql`.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// npm `bin` entry for `dirsql`. The package.json `bin` field points at
|
|
3
|
+
// the compiled version of this file; npm symlinks `node_modules/.bin/dirsql`
|
|
4
|
+
// to it. Always runs the launcher -- nothing else should import this
|
|
5
|
+
// file (test the helpers in `main.ts` / `resolveBinary.ts` instead).
|
|
6
|
+
//
|
|
7
|
+
// A prior `process.argv[1] === import.meta.filename` self-detection
|
|
8
|
+
// guard tripped up the npm-bin symlink: argv[1] is the (unresolved)
|
|
9
|
+
// symlink path, while import.meta.filename is the realpath, and the
|
|
10
|
+
// guard silently skipped main() so `dirsql --version` produced no
|
|
11
|
+
// output (caught by the pack-install build-CI smoke test).
|
|
5
12
|
import { main } from "./main.js";
|
|
6
|
-
|
|
7
|
-
// `dirname(fileURLToPath(import.meta.url))` boilerplate. When this
|
|
8
|
-
// module is the script Node was invoked with, run the launcher.
|
|
9
|
-
if (process.argv[1] === import.meta.filename) {
|
|
10
|
-
main();
|
|
11
|
-
}
|
|
13
|
+
main();
|
|
12
14
|
//# sourceMappingURL=dirsql.js.map
|
package/dist/bin/dirsql.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dirsql.js","sourceRoot":"","sources":["../../ts/bin/dirsql.ts"],"names":[],"mappings":";AACA,
|
|
1
|
+
{"version":3,"file":"dirsql.js","sourceRoot":"","sources":["../../ts/bin/dirsql.ts"],"names":[],"mappings":";AACA,uEAAuE;AACvE,6EAA6E;AAC7E,qEAAqE;AACrE,qEAAqE;AACrE,EAAE;AACF,oEAAoE;AACpE,oEAAoE;AACpE,oEAAoE;AACpE,kEAAkE;AAClE,2DAA2D;AAE3D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,IAAI,EAAE,CAAC"}
|
package/docs/getting-started.md
CHANGED
|
@@ -31,7 +31,7 @@ cargo install dirsql --features cli
|
|
|
31
31
|
|
|
32
32
|
:::
|
|
33
33
|
|
|
34
|
-
See the [CLI
|
|
34
|
+
See the [CLI section](./cli/) for details on the command-line interface, and the [Rust library README](https://github.com/thekevinscott/dirsql/tree/main/packages/rust) for the library-vs-CLI feature split.
|
|
35
35
|
|
|
36
36
|
## Quick start
|
|
37
37
|
|
|
@@ -182,5 +182,5 @@ The filesystem is always the source of truth. The database is rebuilt from files
|
|
|
182
182
|
- [Querying](./guide/querying.md) -- SQL queries and return format
|
|
183
183
|
- [File Watching](./guide/watching.md) -- real-time change events
|
|
184
184
|
- [Async API](./guide/async.md) -- async ready(), query(), and watch()
|
|
185
|
-
- [
|
|
185
|
+
- [Using `dirsql` from the CLI](./cli/) -- `dirsql` runs an HTTP server (`POST /query`, `GET /events` SSE)
|
|
186
186
|
- [Collaboration with CRDTs](./guide/crdt.md) -- multi-writer document merging alongside `dirsql`
|
package/docs/guide/querying.md
CHANGED
|
@@ -8,6 +8,10 @@ canonical: https://thekevinscott.github.io/dirsql/guide/querying
|
|
|
8
8
|
|
|
9
9
|
Once a `DirSQL` instance is created, the initial directory scan is complete and you can run SQL queries against the indexed data.
|
|
10
10
|
|
|
11
|
+
::: tip From the CLI
|
|
12
|
+
The `dirsql` HTTP server exposes the same query interface over [`POST /query`](../cli/http-api.md#post-query). Send `{"sql": "..."}` and get back the same JSON array of row objects. See the [CLI section](../cli/) for the full server setup.
|
|
13
|
+
:::
|
|
14
|
+
|
|
11
15
|
## Basic queries
|
|
12
16
|
|
|
13
17
|
::: code-group
|
package/docs/guide/watching.md
CHANGED
|
@@ -8,6 +8,10 @@ canonical: https://thekevinscott.github.io/dirsql/guide/watching
|
|
|
8
8
|
|
|
9
9
|
`dirsql` can monitor the filesystem for changes and emit events when rows are inserted, updated, or deleted. This is useful for building reactive applications that respond to file changes in real time.
|
|
10
10
|
|
|
11
|
+
::: tip From the CLI
|
|
12
|
+
The `dirsql` HTTP server streams the same events over [`GET /events`](../cli/http-api.md#get-events) as a [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events) stream. Each `data:` payload uses the same JSON schema described in [Event types](#event-types) below. See the [CLI section](../cli/) for the full server setup.
|
|
13
|
+
:::
|
|
14
|
+
|
|
11
15
|
## Starting a watch stream
|
|
12
16
|
|
|
13
17
|
::: code-group
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dirsql",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Ephemeral SQL index over a local directory",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/thekevinscott/dirsql",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"test": "wireit",
|
|
40
40
|
"test:unit": "wireit",
|
|
41
41
|
"test:integration": "wireit",
|
|
42
|
+
"test:e2e": "wireit",
|
|
42
43
|
"coverage": "wireit",
|
|
43
44
|
"lint": "biome check .",
|
|
44
45
|
"lint:fix": "biome check --write .",
|
|
@@ -142,6 +143,21 @@
|
|
|
142
143
|
],
|
|
143
144
|
"output": []
|
|
144
145
|
},
|
|
146
|
+
"test:e2e": {
|
|
147
|
+
"command": "vitest run --dir test-e2e --passWithNoTests",
|
|
148
|
+
"dependencies": [
|
|
149
|
+
"build"
|
|
150
|
+
],
|
|
151
|
+
"files": [
|
|
152
|
+
"ts/**/*.ts",
|
|
153
|
+
"tools/**/*.ts",
|
|
154
|
+
"test-e2e/**/*.ts",
|
|
155
|
+
"vitest.config.ts",
|
|
156
|
+
"../rust/src/**/*.rs",
|
|
157
|
+
"../rust/Cargo.toml"
|
|
158
|
+
],
|
|
159
|
+
"output": []
|
|
160
|
+
},
|
|
145
161
|
"coverage": {
|
|
146
162
|
"command": "vitest run --coverage",
|
|
147
163
|
"dependencies": [
|
|
@@ -175,15 +191,15 @@
|
|
|
175
191
|
]
|
|
176
192
|
},
|
|
177
193
|
"optionalDependencies": {
|
|
178
|
-
"@dirsql/lib-linux-x64-gnu": "0.3.
|
|
179
|
-
"@dirsql/lib-linux-arm64-gnu": "0.3.
|
|
180
|
-
"@dirsql/lib-darwin-x64": "0.3.
|
|
181
|
-
"@dirsql/lib-darwin-arm64": "0.3.
|
|
182
|
-
"@dirsql/lib-win32-x64-msvc": "0.3.
|
|
183
|
-
"@dirsql/cli-linux-x64-gnu": "0.3.
|
|
184
|
-
"@dirsql/cli-linux-arm64-gnu": "0.3.
|
|
185
|
-
"@dirsql/cli-darwin-x64": "0.3.
|
|
186
|
-
"@dirsql/cli-darwin-arm64": "0.3.
|
|
187
|
-
"@dirsql/cli-win32-x64-msvc": "0.3.
|
|
194
|
+
"@dirsql/lib-linux-x64-gnu": "0.3.6",
|
|
195
|
+
"@dirsql/lib-linux-arm64-gnu": "0.3.6",
|
|
196
|
+
"@dirsql/lib-darwin-x64": "0.3.6",
|
|
197
|
+
"@dirsql/lib-darwin-arm64": "0.3.6",
|
|
198
|
+
"@dirsql/lib-win32-x64-msvc": "0.3.6",
|
|
199
|
+
"@dirsql/cli-linux-x64-gnu": "0.3.6",
|
|
200
|
+
"@dirsql/cli-linux-arm64-gnu": "0.3.6",
|
|
201
|
+
"@dirsql/cli-darwin-x64": "0.3.6",
|
|
202
|
+
"@dirsql/cli-darwin-arm64": "0.3.6",
|
|
203
|
+
"@dirsql/cli-win32-x64-msvc": "0.3.6"
|
|
188
204
|
}
|
|
189
205
|
}
|
package/dist/bin/die.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"die.test.d.ts","sourceRoot":"","sources":["../../ts/bin/die.test.ts"],"names":[],"mappings":""}
|
package/dist/bin/die.test.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { die } from "./die.js";
|
|
3
|
-
afterEach(() => vi.restoreAllMocks());
|
|
4
|
-
describe("die", () => {
|
|
5
|
-
describe("by default", () => {
|
|
6
|
-
it("writes a `dirsql: ` prefixed message to stderr", () => {
|
|
7
|
-
const write = vi.spyOn(process.stderr, "write").mockReturnValue(true);
|
|
8
|
-
vi.spyOn(process, "exit").mockImplementation(((code) => {
|
|
9
|
-
throw new Error(`exit:${code}`);
|
|
10
|
-
}));
|
|
11
|
-
expect(() => die("boom")).toThrow("exit:1");
|
|
12
|
-
expect(write).toHaveBeenCalledWith("dirsql: boom\n");
|
|
13
|
-
});
|
|
14
|
-
it("exits with code 1", () => {
|
|
15
|
-
vi.spyOn(process.stderr, "write").mockReturnValue(true);
|
|
16
|
-
const exit = vi.spyOn(process, "exit").mockImplementation(((code) => {
|
|
17
|
-
throw new Error(`exit:${code}`);
|
|
18
|
-
}));
|
|
19
|
-
expect(() => die("boom")).toThrow();
|
|
20
|
-
expect(exit).toHaveBeenCalledWith(1);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
describe("with an explicit exit code", () => {
|
|
24
|
-
it("passes the code to process.exit", () => {
|
|
25
|
-
vi.spyOn(process.stderr, "write").mockReturnValue(true);
|
|
26
|
-
const exit = vi.spyOn(process, "exit").mockImplementation(((code) => {
|
|
27
|
-
throw new Error(`exit:${code}`);
|
|
28
|
-
}));
|
|
29
|
-
expect(() => die("nope", 7)).toThrow();
|
|
30
|
-
expect(exit).toHaveBeenCalledWith(7);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
//# sourceMappingURL=die.test.js.map
|
package/dist/bin/die.test.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"die.test.js","sourceRoot":"","sources":["../../ts/bin/die.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,eAAe,EAAE,CAAC,CAAC;AAEtC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE;IACnB,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;YACxD,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YACtE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAC5C,IAA6B,EAC7B,EAAE;gBACF,MAAM,IAAI,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;YAClC,CAAC,CAAwB,CAAC,CAAC;YAE3B,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,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,CAAC;YACvC,MAAM,CAAC,IAAI,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/bin/main.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"main.test.d.ts","sourceRoot":"","sources":["../../ts/bin/main.test.ts"],"names":[],"mappings":""}
|
package/dist/bin/main.test.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
vi.mock("./resolveBinary", () => ({ resolveBinary: vi.fn() }));
|
|
3
|
-
vi.mock("node:child_process", () => ({ spawnSync: vi.fn() }));
|
|
4
|
-
import { spawnSync } from "node:child_process";
|
|
5
|
-
import { main } from "./main.js";
|
|
6
|
-
import { resolveBinary } from "./resolveBinary.js";
|
|
7
|
-
const spawnSyncMock = vi.mocked(spawnSync);
|
|
8
|
-
const resolveBinaryMock = vi.mocked(resolveBinary);
|
|
9
|
-
afterEach(() => vi.restoreAllMocks());
|
|
10
|
-
function stubExit() {
|
|
11
|
-
return vi.spyOn(process, "exit").mockImplementation(((code) => {
|
|
12
|
-
throw new Error(`exit:${code}`);
|
|
13
|
-
}));
|
|
14
|
-
}
|
|
15
|
-
function stubStderr() {
|
|
16
|
-
vi.spyOn(process.stderr, "write").mockReturnValue(true);
|
|
17
|
-
}
|
|
18
|
-
function stubKill() {
|
|
19
|
-
return vi.spyOn(process, "kill").mockImplementation(() => true);
|
|
20
|
-
}
|
|
21
|
-
describe("main", () => {
|
|
22
|
-
describe("on success", () => {
|
|
23
|
-
it("resolves the binary, spawns it with argv, and exits with the child's status", () => {
|
|
24
|
-
resolveBinaryMock.mockReturnValue("/real/dirsql");
|
|
25
|
-
spawnSyncMock.mockReturnValue({
|
|
26
|
-
status: 0,
|
|
27
|
-
signal: null,
|
|
28
|
-
pid: 123,
|
|
29
|
-
output: [],
|
|
30
|
-
stdout: Buffer.from(""),
|
|
31
|
-
stderr: Buffer.from(""),
|
|
32
|
-
});
|
|
33
|
-
const exit = stubExit();
|
|
34
|
-
expect(() => main(["--help"])).toThrow("exit:0");
|
|
35
|
-
expect(resolveBinaryMock).toHaveBeenCalledTimes(1);
|
|
36
|
-
expect(spawnSyncMock).toHaveBeenCalledWith("/real/dirsql", ["--help"], {
|
|
37
|
-
stdio: "inherit",
|
|
38
|
-
});
|
|
39
|
-
expect(exit).toHaveBeenCalledWith(0);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
describe("when the child exits non-zero", () => {
|
|
43
|
-
it("forwards the exit code", () => {
|
|
44
|
-
resolveBinaryMock.mockReturnValue("/real/dirsql");
|
|
45
|
-
spawnSyncMock.mockReturnValue({
|
|
46
|
-
status: 42,
|
|
47
|
-
signal: null,
|
|
48
|
-
pid: 1,
|
|
49
|
-
output: [],
|
|
50
|
-
stdout: Buffer.from(""),
|
|
51
|
-
stderr: Buffer.from(""),
|
|
52
|
-
});
|
|
53
|
-
const exit = stubExit();
|
|
54
|
-
expect(() => main([])).toThrow("exit:42");
|
|
55
|
-
expect(exit).toHaveBeenCalledWith(42);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
describe("when spawn fails to launch the child", () => {
|
|
59
|
-
it("dies with the spawn error message and exits 1", () => {
|
|
60
|
-
resolveBinaryMock.mockReturnValue("/real/dirsql");
|
|
61
|
-
spawnSyncMock.mockReturnValue({
|
|
62
|
-
status: null,
|
|
63
|
-
signal: null,
|
|
64
|
-
pid: 0,
|
|
65
|
-
output: [],
|
|
66
|
-
stdout: Buffer.from(""),
|
|
67
|
-
stderr: Buffer.from(""),
|
|
68
|
-
error: new Error("ENOENT"),
|
|
69
|
-
});
|
|
70
|
-
stubStderr();
|
|
71
|
-
const exit = stubExit();
|
|
72
|
-
expect(() => main([])).toThrow();
|
|
73
|
-
expect(exit).toHaveBeenCalledWith(1);
|
|
74
|
-
expect(process.stderr.write).toHaveBeenCalledWith(expect.stringContaining("ENOENT"));
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
describe("when the child dies from a signal", () => {
|
|
78
|
-
it("re-raises the same signal against itself", () => {
|
|
79
|
-
resolveBinaryMock.mockReturnValue("/real/dirsql");
|
|
80
|
-
spawnSyncMock.mockReturnValue({
|
|
81
|
-
status: null,
|
|
82
|
-
signal: "SIGINT",
|
|
83
|
-
pid: 1,
|
|
84
|
-
output: [],
|
|
85
|
-
stdout: Buffer.from(""),
|
|
86
|
-
stderr: Buffer.from(""),
|
|
87
|
-
});
|
|
88
|
-
const kill = stubKill();
|
|
89
|
-
const exit = stubExit();
|
|
90
|
-
expect(() => main([])).toThrow();
|
|
91
|
-
expect(kill).toHaveBeenCalledWith(process.pid, "SIGINT");
|
|
92
|
-
expect(exit).toHaveBeenCalledWith(1);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
describe("when argv is omitted", () => {
|
|
96
|
-
it("defaults to process.argv.slice(2)", () => {
|
|
97
|
-
resolveBinaryMock.mockReturnValue("/real/dirsql");
|
|
98
|
-
spawnSyncMock.mockReturnValue({
|
|
99
|
-
status: 0,
|
|
100
|
-
signal: null,
|
|
101
|
-
pid: 1,
|
|
102
|
-
output: [],
|
|
103
|
-
stdout: Buffer.from(""),
|
|
104
|
-
stderr: Buffer.from(""),
|
|
105
|
-
});
|
|
106
|
-
vi.stubGlobal("process", {
|
|
107
|
-
...process,
|
|
108
|
-
argv: ["node", "bin", "a", "b"],
|
|
109
|
-
});
|
|
110
|
-
stubExit();
|
|
111
|
-
try {
|
|
112
|
-
main();
|
|
113
|
-
}
|
|
114
|
-
catch {
|
|
115
|
-
// process.exit is stubbed to throw
|
|
116
|
-
}
|
|
117
|
-
expect(spawnSyncMock).toHaveBeenCalledWith("/real/dirsql", ["a", "b"], expect.any(Object));
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
//# sourceMappingURL=main.test.js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CAAC,EAAE,CAAC;aACf,CAAC,CAAC;YACZ,EAAE,CAAC,UAAU,CAAC,SAAS,EAAE;gBACvB,GAAG,OAAO;gBACV,IAAI,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC;aAChC,CAAC,CAAC;YACH,QAAQ,EAAE,CAAC;YAEX,IAAI,CAAC;gBACH,IAAI,EAAE,CAAC;YACT,CAAC;YAAC,MAAM,CAAC;gBACP,mCAAmC;YACrC,CAAC;YACD,MAAM,CAAC,aAAa,CAAC,CAAC,oBAAoB,CACxC,cAAc,EACd,CAAC,GAAG,EAAE,GAAG,CAAC,EACV,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CACnB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolveBinary.test.d.ts","sourceRoot":"","sources":["../../ts/bin/resolveBinary.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { defaultResolver, resolveBinary, } from "./resolveBinary.js";
|
|
3
|
-
afterEach(() => {
|
|
4
|
-
vi.restoreAllMocks();
|
|
5
|
-
});
|
|
6
|
-
function exitThrower() {
|
|
7
|
-
return vi.spyOn(process, "exit").mockImplementation(((code) => {
|
|
8
|
-
throw new Error(`exit:${code}`);
|
|
9
|
-
}));
|
|
10
|
-
}
|
|
11
|
-
describe("defaultResolver", () => {
|
|
12
|
-
it("returns a function that resolves node built-ins", () => {
|
|
13
|
-
const resolve = defaultResolver();
|
|
14
|
-
expect(typeof resolve).toBe("function");
|
|
15
|
-
// `node:fs` is always resolvable from any Node-reachable module.
|
|
16
|
-
expect(resolve("node:fs")).toBe("node:fs");
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
describe("resolveBinary", () => {
|
|
20
|
-
describe("with a supported platform key", () => {
|
|
21
|
-
it("returns the resolver's result for the matching package", () => {
|
|
22
|
-
const resolver = vi.fn().mockReturnValue("/real/linux/dirsql");
|
|
23
|
-
const path = resolveBinary("linux-x64", resolver);
|
|
24
|
-
expect(path).toBe("/real/linux/dirsql");
|
|
25
|
-
expect(resolver).toHaveBeenCalledWith(expect.stringContaining("@dirsql/cli-linux-x64-gnu"));
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
describe("with an unsupported platform key", () => {
|
|
29
|
-
it("dies with a `cargo install` hint", () => {
|
|
30
|
-
vi.spyOn(process.stderr, "write").mockReturnValue(true);
|
|
31
|
-
const exit = exitThrower();
|
|
32
|
-
expect(() => resolveBinary("sunos-sparc", () => "")).toThrow();
|
|
33
|
-
expect(exit).toHaveBeenCalledWith(1);
|
|
34
|
-
expect(process.stderr.write).toHaveBeenCalledWith(expect.stringContaining("no prebuilt binary for sunos-sparc"));
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
describe("on Windows", () => {
|
|
38
|
-
it("appends .exe to the resolved binary name", () => {
|
|
39
|
-
vi.stubGlobal("process", { ...process, platform: "win32" });
|
|
40
|
-
const resolver = vi
|
|
41
|
-
.fn()
|
|
42
|
-
.mockReturnValue("C:\\fake\\dirsql.exe");
|
|
43
|
-
resolveBinary("win32-x64", resolver);
|
|
44
|
-
expect(resolver).toHaveBeenCalledWith(expect.stringMatching(/dirsql\.exe$/));
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
describe("when the optional dep is not installed", () => {
|
|
48
|
-
it("dies with an `--no-optional` hint", () => {
|
|
49
|
-
vi.spyOn(process.stderr, "write").mockReturnValue(true);
|
|
50
|
-
const exit = exitThrower();
|
|
51
|
-
const resolver = () => {
|
|
52
|
-
throw new Error("Cannot find module");
|
|
53
|
-
};
|
|
54
|
-
expect(() => resolveBinary("linux-x64", resolver)).toThrow();
|
|
55
|
-
expect(exit).toHaveBeenCalledWith(1);
|
|
56
|
-
expect(process.stderr.write).toHaveBeenCalledWith(expect.stringContaining("is not installed"));
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
//# sourceMappingURL=resolveBinary.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolveBinary.test.js","sourceRoot":"","sources":["../../ts/bin/resolveBinary.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAEL,eAAe,EACf,aAAa,GACd,MAAM,oBAAoB,CAAC;AAE5B,SAAS,CAAC,GAAG,EAAE;IACb,EAAE,CAAC,eAAe,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEH,SAAS,WAAW;IAClB,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,kBAAkB,CAAC,CAAC,CACnD,IAA6B,EAC7B,EAAE;QACF,MAAM,IAAI,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IAClC,CAAC,CAAwB,CAAC,CAAC;AAC7B,CAAC;AAED,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;QACzD,MAAM,OAAO,GAAG,eAAe,EAAE,CAAC;QAClC,MAAM,CAAC,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxC,iEAAiE;QACjE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;QAC7C,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;YAChE,MAAM,QAA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B,CAAC,CAAC;YAC3C,aAAa,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;YACrC,MAAM,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CACnC,MAAM,CAAC,cAAc,CAAC,cAAc,CAAC,CACtC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,wCAAwC,EAAE,GAAG,EAAE;QACtD,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;YAC3C,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YACxD,MAAM,IAAI,GAAG,WAAW,EAAE,CAAC;YAC3B,MAAM,QAAQ,GAAa,GAAG,EAAE;gBAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;YACxC,CAAC,CAAC;YACF,MAAM,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;YAC7D,MAAM,CAAC,IAAI,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;YACrC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,oBAAoB,CAC/C,MAAM,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAC5C,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/docs/guide/cli.md
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
canonical: https://thekevinscott.github.io/dirsql/guide/cli
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Command-Line Interface
|
|
6
|
-
|
|
7
|
-
> Online: <https://thekevinscott.github.io/dirsql/guide/cli>
|
|
8
|
-
|
|
9
|
-
`dirsql` starts an HTTP server that exposes identical SDK functionality.
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
12
|
-
|
|
13
|
-
::: code-group
|
|
14
|
-
|
|
15
|
-
```bash [npm]
|
|
16
|
-
npx dirsql
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
```bash [PyPI]
|
|
20
|
-
uvx dirsql
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
```bash [Cargo]
|
|
24
|
-
# Installs the binary only (non-default feature)
|
|
25
|
-
cargo install dirsql --features cli
|
|
26
|
-
dirsql
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
:::
|
|
30
|
-
|
|
31
|
-
::: tip For Rust library consumers
|
|
32
|
-
The `cli` feature is **opt-in**. Adding `dirsql` as a library dependency (`cargo add dirsql`) pulls no CLI dependencies — only the core library. See the [Rust library README](https://github.com/thekevinscott/dirsql/tree/main/packages/rust) for details.
|
|
33
|
-
:::
|
|
34
|
-
|
|
35
|
-
## Subcommands
|
|
36
|
-
|
|
37
|
-
| Command | Purpose |
|
|
38
|
-
|---|---|
|
|
39
|
-
| `dirsql` (no subcommand) | Start the long-lived HTTP server (default behavior, see below). |
|
|
40
|
-
| `dirsql init` | Generate a starter `.dirsql.toml` from the contents of a directory. See [Generating a Config](./init.md). |
|
|
41
|
-
|
|
42
|
-
## Running the server
|
|
43
|
-
|
|
44
|
-
Run `dirsql` from the directory containing your files:
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
dirsql
|
|
48
|
-
|
|
49
|
-
$ Running at localhost:7117
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Flags
|
|
53
|
-
|
|
54
|
-
| Flag | Default | Description |
|
|
55
|
-
|---|---|---|
|
|
56
|
-
| `--config <path>` | `./.dirsql.toml` | Path to the config file. The index is rooted at the directory containing this file. |
|
|
57
|
-
| `--host <addr>` | `localhost` | Bind address |
|
|
58
|
-
| `--port <n>` | `7117` | TCP port to bind |
|
|
59
|
-
|
|
60
|
-
## HTTP API
|
|
61
|
-
|
|
62
|
-
### `POST /query`
|
|
63
|
-
|
|
64
|
-
Run a SQL query. Request body is JSON:
|
|
65
|
-
|
|
66
|
-
```json
|
|
67
|
-
{"sql": "SELECT title, author FROM posts WHERE draft = 0"}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
Response is a JSON array of row objects:
|
|
71
|
-
|
|
72
|
-
```json
|
|
73
|
-
[
|
|
74
|
-
{"title": "Hello World", "author": "alice"},
|
|
75
|
-
{"title": "Second Post", "author": "bob"}
|
|
76
|
-
]
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
On error, the server returns a non-2xx status with a JSON body:
|
|
80
|
-
|
|
81
|
-
```json
|
|
82
|
-
{"error": "syntax error near \"SLECT\""}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Malformed SQL returns `400`, not `500` — the client sent bad input. Missing / unreadable config returns `503`.
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
curl -s http://localhost:7117/query \
|
|
89
|
-
-H 'content-type: application/json' \
|
|
90
|
-
-d '{"sql":"SELECT COUNT(*) AS n FROM posts"}' \
|
|
91
|
-
| jq
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### `GET /events`
|
|
95
|
-
|
|
96
|
-
Opens a [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events) stream of change events. Each `data:` payload is the same JSON schema the SDK emits from [`db.watch()`](./watching.md#event-types):
|
|
97
|
-
|
|
98
|
-
```
|
|
99
|
-
event: row
|
|
100
|
-
data: {"action":"insert","table":"posts","file_path":"posts/hello.json","row":{"title":"Hello World","author":"alice"},"old_row":null}
|
|
101
|
-
|
|
102
|
-
event: row
|
|
103
|
-
data: {"action":"update","table":"posts","file_path":"posts/hello.json","row":{"title":"Hello, world","author":"alice"},"old_row":{"title":"Hello World","author":"alice"}}
|
|
104
|
-
|
|
105
|
-
event: row
|
|
106
|
-
data: {"action":"delete","table":"posts","file_path":"posts/second.json","row":{"title":"Second Post","author":"bob"},"old_row":null}
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
Errors during extraction appear as `{"action":"error",...}` events on the same stream. They do **not** terminate the stream — a malformed file is a per-event problem, not a server-wide one.
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
curl -N http://localhost:7117/events
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
## Piping event streams
|
|
116
|
-
|
|
117
|
-
The SSE stream is easy to tee into shell tools with `curl -N` plus `jq`:
|
|
118
|
-
|
|
119
|
-
```bash
|
|
120
|
-
# Log every delete to a file
|
|
121
|
-
curl -N http://localhost:7117/events \
|
|
122
|
-
| jq -cR 'fromjson? | select(.action=="delete")' \
|
|
123
|
-
>> deletes.log
|
|
124
|
-
|
|
125
|
-
# Alert on errors
|
|
126
|
-
curl -N http://localhost:7117/events \
|
|
127
|
-
| jq -c 'fromjson? | select(.action=="error")' \
|
|
128
|
-
| while read -r line; do notify-send "dirsql error" "$line"; done
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
(The `fromjson?` wrapping strips the `data:` framing; drop it if your SSE client is already parsing frames.)
|
package/docs/guide/config.md
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
canonical: https://thekevinscott.github.io/dirsql/guide/config
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Configuration File
|
|
6
|
-
|
|
7
|
-
> Online: <https://thekevinscott.github.io/dirsql/guide/config>
|
|
8
|
-
|
|
9
|
-
`dirsql` can be configured with a `.dirsql.toml` file. Tables defined this
|
|
10
|
-
way produce **one row per matched file**. Each row's columns come from
|
|
11
|
-
filesystem facts:
|
|
12
|
-
|
|
13
|
-
- **Glob path captures** — named `{placeholder}` segments in the glob.
|
|
14
|
-
- **Stat virtuals** — reserved `_`-prefixed columns for path-derived and
|
|
15
|
-
stat-derived metadata.
|
|
16
|
-
|
|
17
|
-
Content interpretation (parsing JSON, CSV, frontmatter, etc.) is **not**
|
|
18
|
-
configured in `.dirsql.toml`. If you need columns derived from file
|
|
19
|
-
contents, register a programmatic [`Table`](./tables.md) whose `extract`
|
|
20
|
-
function does the parsing in your host language.
|
|
21
|
-
|
|
22
|
-
## Basic Example
|
|
23
|
-
|
|
24
|
-
```toml
|
|
25
|
-
[dirsql]
|
|
26
|
-
ignore = ["node_modules/**", ".git/**"]
|
|
27
|
-
|
|
28
|
-
[[table]]
|
|
29
|
-
ddl = "CREATE TABLE posts (_path TEXT, _basename TEXT, _size INTEGER, _mtime INTEGER)"
|
|
30
|
-
glob = "posts/*.md"
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Each `posts/*.md` file produces one row. The DDL declares which stat
|
|
34
|
-
virtuals are surfaced as SQL columns.
|
|
35
|
-
|
|
36
|
-
## Loading a Config File
|
|
37
|
-
|
|
38
|
-
Pass the config file path to the `DirSQL` constructor:
|
|
39
|
-
|
|
40
|
-
::: code-group
|
|
41
|
-
|
|
42
|
-
```python [Python]
|
|
43
|
-
from dirsql import DirSQL
|
|
44
|
-
|
|
45
|
-
db = DirSQL(config="./my-project/.dirsql.toml")
|
|
46
|
-
await db.ready()
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
```rust [Rust]
|
|
50
|
-
use dirsql::DirSQL;
|
|
51
|
-
|
|
52
|
-
let db = DirSQL::builder()
|
|
53
|
-
.config("./my-project/.dirsql.toml")
|
|
54
|
-
.build()?;
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
```typescript [TypeScript]
|
|
58
|
-
import { DirSQL } from "dirsql";
|
|
59
|
-
|
|
60
|
-
// String argument is interpreted as a config file path.
|
|
61
|
-
const db = new DirSQL("./my-project/.dirsql.toml");
|
|
62
|
-
await db.ready;
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
:::
|
|
66
|
-
|
|
67
|
-
By default, the root directory scanned is the config file's parent
|
|
68
|
-
directory. Override it by passing `root` explicitly (the explicit value
|
|
69
|
-
wins and a warning is emitted) or by declaring `[dirsql].root` in the
|
|
70
|
-
config file itself.
|
|
71
|
-
|
|
72
|
-
## Root Directory
|
|
73
|
-
|
|
74
|
-
By default, the config file's parent directory is the scan root. To index
|
|
75
|
-
a different location, declare `[dirsql].root` (relative paths are resolved
|
|
76
|
-
relative to the config file's parent):
|
|
77
|
-
|
|
78
|
-
```toml
|
|
79
|
-
[dirsql]
|
|
80
|
-
root = "../data"
|
|
81
|
-
ignore = ["node_modules/**"]
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## Stat Virtuals
|
|
85
|
-
|
|
86
|
-
Every config-defined table can expose any of these reserved columns. Add
|
|
87
|
-
the ones you want to your DDL; the rest are silently dropped.
|
|
88
|
-
|
|
89
|
-
| Column | Type | Source |
|
|
90
|
-
|--------|---------|--------|
|
|
91
|
-
| `_path` | TEXT | The file's path relative to the scan root. |
|
|
92
|
-
| `_basename` | TEXT | The filename including extension. |
|
|
93
|
-
| `_dir` | TEXT | The parent directory path (relative to root). |
|
|
94
|
-
| `_ext` | TEXT | The file extension, lowercased, no leading dot. |
|
|
95
|
-
| `_size` | INTEGER | Size in bytes. |
|
|
96
|
-
| `_mtime` | INTEGER | Last-modified time, unix seconds. |
|
|
97
|
-
| `_ctime` | INTEGER | Created/changed time, unix seconds. |
|
|
98
|
-
|
|
99
|
-
Example query:
|
|
100
|
-
|
|
101
|
-
```sql
|
|
102
|
-
SELECT _basename, _size
|
|
103
|
-
FROM posts
|
|
104
|
-
WHERE _mtime > strftime('%s', '2024-01-01')
|
|
105
|
-
ORDER BY _mtime DESC;
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## Path Captures
|
|
109
|
-
|
|
110
|
-
Use `{name}` in glob patterns to extract path segments as columns. Add a
|
|
111
|
-
matching column name to the DDL and the capture is auto-populated:
|
|
112
|
-
|
|
113
|
-
```toml
|
|
114
|
-
[[table]]
|
|
115
|
-
ddl = "CREATE TABLE comments (thread_id TEXT, _basename TEXT, _mtime INTEGER)"
|
|
116
|
-
glob = "_comments/{thread_id}/*.jsonl"
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
A file at `_comments/abc123/2024-05-05.jsonl` produces a row with
|
|
120
|
-
`thread_id = "abc123"`, `_basename = "2024-05-05.jsonl"`, and `_mtime` set
|
|
121
|
-
to the file's modification time.
|
|
122
|
-
|
|
123
|
-
## Ignore Patterns
|
|
124
|
-
|
|
125
|
-
The `ignore` list skips files and directories entirely (not even scanned):
|
|
126
|
-
|
|
127
|
-
```toml
|
|
128
|
-
[dirsql]
|
|
129
|
-
ignore = ["node_modules/**", ".git/**", "*.pyc", "__pycache__/**"]
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
The top-level `.dirsql/` directory is always excluded, whether you list it
|
|
133
|
-
or not — it is a reserved namespace for `dirsql`'s own metadata (see
|
|
134
|
-
[Persistence](./persistence.md)).
|
|
135
|
-
|
|
136
|
-
## Persistence
|
|
137
|
-
|
|
138
|
-
Set `persist = true` to keep the SQLite database on disk between runs
|
|
139
|
-
instead of rebuilding from scratch on every startup:
|
|
140
|
-
|
|
141
|
-
```toml
|
|
142
|
-
[dirsql]
|
|
143
|
-
persist = true
|
|
144
|
-
# persist_path = ".dirsql/cache.db" # optional; this is the default
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
See [Persistence](./persistence.md) for the full reconcile algorithm,
|
|
148
|
-
storage layout, and limitations.
|
|
149
|
-
|
|
150
|
-
## Strict Mode
|
|
151
|
-
|
|
152
|
-
By default, auto-injected virtuals that aren't in the DDL are silently
|
|
153
|
-
dropped, and undeclared user-extract keys are dropped. Enable strict mode
|
|
154
|
-
to error when an extract emits keys not declared in the DDL:
|
|
155
|
-
|
|
156
|
-
```toml
|
|
157
|
-
[[table]]
|
|
158
|
-
ddl = "CREATE TABLE comments (thread_id TEXT)"
|
|
159
|
-
glob = "_comments/{thread_id}/*.jsonl"
|
|
160
|
-
strict = true
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
Strict mode does **not** apply to auto-injected stat virtuals — those are
|
|
164
|
-
always filtered to the DDL's declared columns regardless. Strict mode
|
|
165
|
-
applies only to keys produced by an extract callback (relevant for
|
|
166
|
-
programmatic [tables](./tables.md)).
|
|
167
|
-
|
|
168
|
-
## Full Example
|
|
169
|
-
|
|
170
|
-
```toml
|
|
171
|
-
[dirsql]
|
|
172
|
-
ignore = ["node_modules/**", ".git/**", "dist/**"]
|
|
173
|
-
|
|
174
|
-
[[table]]
|
|
175
|
-
ddl = "CREATE TABLE comments (thread_id TEXT, _basename TEXT, _mtime INTEGER)"
|
|
176
|
-
glob = "_comments/{thread_id}/*.jsonl"
|
|
177
|
-
|
|
178
|
-
[[table]]
|
|
179
|
-
ddl = "CREATE TABLE documents (_path TEXT, _basename TEXT, _size INTEGER)"
|
|
180
|
-
glob = "**/index.md"
|
|
181
|
-
|
|
182
|
-
[[table]]
|
|
183
|
-
ddl = "CREATE TABLE logs (_path TEXT, _size INTEGER, _mtime INTEGER)"
|
|
184
|
-
glob = "logs/*.csv"
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
## When you need parsed content
|
|
188
|
-
|
|
189
|
-
`.dirsql.toml` does not parse file contents. For columns derived from the
|
|
190
|
-
*inside* of files (frontmatter keys, JSON values, CSV cells, etc.),
|
|
191
|
-
register a programmatic [`Table`](./tables.md) instead, and parse the
|
|
192
|
-
bytes in your host language. Glob captures and stat virtuals are still
|
|
193
|
-
auto-injected into rows produced by your extract.
|
package/docs/guide/init.md
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
canonical: https://thekevinscott.github.io/dirsql/guide/init
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Generating a config with `dirsql init`
|
|
6
|
-
|
|
7
|
-
> Online: <https://thekevinscott.github.io/dirsql/guide/init>
|
|
8
|
-
|
|
9
|
-
`dirsql init` generates a `.dirsql.toml` by running `claude` over the target directory.
|
|
10
|
-
|
|
11
|
-
The output is limited to filesystem-fact tables. For content-aware schemas, see [Defining Tables](./tables.md).
|
|
12
|
-
|
|
13
|
-
## Examples
|
|
14
|
-
|
|
15
|
-
### Mixed files
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
my-downloads/
|
|
19
|
-
├── archive.zip
|
|
20
|
-
├── invoice.pdf
|
|
21
|
-
├── notes.txt
|
|
22
|
-
└── photo.jpg
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
```toml
|
|
26
|
-
[[table]]
|
|
27
|
-
ddl = "CREATE TABLE files (_path TEXT, _ext TEXT, _size INTEGER)"
|
|
28
|
-
glob = "*"
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### Path captures
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
photos/
|
|
35
|
-
├── 2024-01/
|
|
36
|
-
│ ├── beach.jpg
|
|
37
|
-
│ └── sunset.jpg
|
|
38
|
-
└── 2024-02/
|
|
39
|
-
├── snow.jpg
|
|
40
|
-
└── mountain.jpg
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
```toml
|
|
44
|
-
[[table]]
|
|
45
|
-
ddl = "CREATE TABLE photos (month TEXT, _basename TEXT, _mtime INTEGER)"
|
|
46
|
-
glob = "{month}/*.jpg"
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### Multiple tables
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
my-blog/
|
|
53
|
-
├── posts/
|
|
54
|
-
│ ├── hello-world.md
|
|
55
|
-
│ └── second.md
|
|
56
|
-
└── _comments/
|
|
57
|
-
└── hello-world/
|
|
58
|
-
├── 2024-01-15.jsonl
|
|
59
|
-
└── 2024-02-03.jsonl
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
```toml
|
|
63
|
-
[[table]]
|
|
64
|
-
ddl = "CREATE TABLE posts (_basename TEXT, _mtime INTEGER, _size INTEGER)"
|
|
65
|
-
glob = "posts/*.md"
|
|
66
|
-
|
|
67
|
-
[[table]]
|
|
68
|
-
ddl = "CREATE TABLE comments (thread_id TEXT, _basename TEXT, _mtime INTEGER)"
|
|
69
|
-
glob = "_comments/{thread_id}/*.jsonl"
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
`init` will not overwrite an existing config without `--force`.
|
|
73
|
-
|
|
74
|
-
## Flags
|
|
75
|
-
|
|
76
|
-
| Flag | Default | Description |
|
|
77
|
-
|---|---|---|
|
|
78
|
-
| `--root <path>` | cwd | Directory to scan |
|
|
79
|
-
| `--output <path>` | `<root>/.dirsql.toml` | Output path |
|
|
80
|
-
| `--force` | off | Overwrite if the output exists |
|
|
81
|
-
|
|
82
|
-
## Authentication
|
|
83
|
-
|
|
84
|
-
Requires `claude` on `PATH` and signed in. There is no separate API key. If `claude` is missing, `dirsql init` raises an exception.
|