dirsql 0.4.141 → 0.4.143
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/core.d.ts +3 -3
- package/dist/dirsql.d.ts +17 -2
- package/dist/dirsql.js +12 -4
- package/dist/index.d.ts +1 -1
- package/docs/reference/sdk.md +69 -3
- package/package.json +6 -6
package/dist/core.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ExtensionSpec, QueryResult, RowEvent, ScanFailure } from "./dirsql.js";
|
|
1
|
+
import type { ExtensionSpec, QueryParams, QueryResult, RowEvent, ScanFailure } from "./dirsql.js";
|
|
2
2
|
import type { TableDef } from "./table.js";
|
|
3
3
|
export interface NativeDirSQL {
|
|
4
|
-
query(sql: string): Promise<Record<string, unknown>[]>;
|
|
5
|
-
queryOrdered(sql: string): Promise<QueryResult>;
|
|
4
|
+
query(sql: string, params?: QueryParams): Promise<Record<string, unknown>[]>;
|
|
5
|
+
queryOrdered(sql: string, params?: QueryParams): Promise<QueryResult>;
|
|
6
6
|
startWatcher(): void;
|
|
7
7
|
pollEvents(timeoutMs: number): Promise<RowEvent[]>;
|
|
8
8
|
scanFailures(): ScanFailure[];
|
package/dist/dirsql.d.ts
CHANGED
|
@@ -82,6 +82,13 @@ export interface RowEvent {
|
|
|
82
82
|
error?: string | null;
|
|
83
83
|
filePath?: string | null;
|
|
84
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Bind parameters for {@link DirSQL.query}: an array fills `?` placeholders
|
|
87
|
+
* in order; a plain object fills `:name`, `@name` and `$name` placeholders,
|
|
88
|
+
* keyed by the name without its prefix. Values bind as SQLite's native types:
|
|
89
|
+
* `null`, `number`, `bigint`, `boolean`, `string`, `Buffer` / `Uint8Array`.
|
|
90
|
+
*/
|
|
91
|
+
export type QueryParams = readonly unknown[] | Record<string, unknown> | null;
|
|
85
92
|
/** The result of {@link DirSQL.queryOrdered}. */
|
|
86
93
|
export interface QueryResult {
|
|
87
94
|
/**
|
|
@@ -159,8 +166,16 @@ export declare class DirSQL {
|
|
|
159
166
|
* Awaits the initial scan if it has not yet finished, then runs the
|
|
160
167
|
* query on the libuv threadpool, so the JS event loop stays responsive
|
|
161
168
|
* even for large result sets or long-running queries.
|
|
169
|
+
*
|
|
170
|
+
* `params` binds to the statement's placeholders through SQLite, so the
|
|
171
|
+
* values never enter the SQL text:
|
|
172
|
+
*
|
|
173
|
+
* ```ts
|
|
174
|
+
* await db.query("SELECT path FROM './*.json' WHERE content ->> 'a' = :a", { a: text });
|
|
175
|
+
* await db.query("SELECT * FROM notes WHERE author = ?", ["ann"]);
|
|
176
|
+
* ```
|
|
162
177
|
*/
|
|
163
|
-
query(sql: string): Promise<Record<string, unknown>[]>;
|
|
178
|
+
query(sql: string, params?: QueryParams): Promise<Record<string, unknown>[]>;
|
|
164
179
|
/**
|
|
165
180
|
* {@link query}, plus the column order the SELECT list names. Use it to
|
|
166
181
|
* render columns in the order the caller asked for.
|
|
@@ -170,7 +185,7 @@ export declare class DirSQL {
|
|
|
170
185
|
* // columns: ["path", "size"]
|
|
171
186
|
* ```
|
|
172
187
|
*/
|
|
173
|
-
queryOrdered(sql: string): Promise<QueryResult>;
|
|
188
|
+
queryOrdered(sql: string, params?: QueryParams): Promise<QueryResult>;
|
|
174
189
|
/**
|
|
175
190
|
* The files the initial scan could not index, each with its root-relative
|
|
176
191
|
* `path` and the hook's own `message`.
|
package/dist/dirsql.js
CHANGED
|
@@ -104,10 +104,18 @@ export class DirSQL {
|
|
|
104
104
|
* Awaits the initial scan if it has not yet finished, then runs the
|
|
105
105
|
* query on the libuv threadpool, so the JS event loop stays responsive
|
|
106
106
|
* even for large result sets or long-running queries.
|
|
107
|
+
*
|
|
108
|
+
* `params` binds to the statement's placeholders through SQLite, so the
|
|
109
|
+
* values never enter the SQL text:
|
|
110
|
+
*
|
|
111
|
+
* ```ts
|
|
112
|
+
* await db.query("SELECT path FROM './*.json' WHERE content ->> 'a' = :a", { a: text });
|
|
113
|
+
* await db.query("SELECT * FROM notes WHERE author = ?", ["ann"]);
|
|
114
|
+
* ```
|
|
107
115
|
*/
|
|
108
|
-
async query(sql) {
|
|
116
|
+
async query(sql, params) {
|
|
109
117
|
await this.ready;
|
|
110
|
-
return this._inner.query(sql);
|
|
118
|
+
return this._inner.query(sql, params);
|
|
111
119
|
}
|
|
112
120
|
/**
|
|
113
121
|
* {@link query}, plus the column order the SELECT list names. Use it to
|
|
@@ -118,9 +126,9 @@ export class DirSQL {
|
|
|
118
126
|
* // columns: ["path", "size"]
|
|
119
127
|
* ```
|
|
120
128
|
*/
|
|
121
|
-
async queryOrdered(sql) {
|
|
129
|
+
async queryOrdered(sql, params) {
|
|
122
130
|
await this.ready;
|
|
123
|
-
return this._inner.queryOrdered(sql);
|
|
131
|
+
return this._inner.queryOrdered(sql, params);
|
|
124
132
|
}
|
|
125
133
|
/**
|
|
126
134
|
* The files the initial scan could not index, each with its root-relative
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { DirSQL } from "./dirsql.js";
|
|
2
|
-
export type { DirSQLOptions, ExtensionSpec, QueryResult, RowEvent, ScanFailure, } from "./dirsql.js";
|
|
2
|
+
export type { DirSQLOptions, ExtensionSpec, QueryParams, QueryResult, RowEvent, ScanFailure, } from "./dirsql.js";
|
|
3
3
|
export { Table } from "./table.js";
|
|
4
4
|
export type { TableDef } from "./table.js";
|
package/docs/reference/sdk.md
CHANGED
|
@@ -208,22 +208,87 @@ observe construction errors before issuing a query.
|
|
|
208
208
|
::: code-group
|
|
209
209
|
|
|
210
210
|
```python [Python]
|
|
211
|
-
await db.query(sql: str) -> list[dict]
|
|
211
|
+
await db.query(sql: str, params: Sequence | Mapping | None = None) -> list[dict]
|
|
212
212
|
```
|
|
213
213
|
|
|
214
214
|
```typescript [TypeScript]
|
|
215
|
-
await db.query(sql: string) -> Record<string, unknown>[]
|
|
215
|
+
await db.query(sql: string, params?: unknown[] | Record<string, unknown> | null) -> Record<string, unknown>[]
|
|
216
216
|
// Runs on the libuv threadpool; the JS event loop stays responsive.
|
|
217
217
|
```
|
|
218
218
|
|
|
219
219
|
```rust [Rust]
|
|
220
220
|
db.query(sql: &str) -> Result<Vec<Row>> // Row = HashMap<String, Value>
|
|
221
|
+
db.query_with(sql: &str, params: &Params) -> Result<Vec<Row>>
|
|
221
222
|
```
|
|
222
223
|
|
|
223
224
|
:::
|
|
224
225
|
|
|
225
226
|
Executes a SQL query and returns rows keyed by column name.
|
|
226
227
|
|
|
228
|
+
**Bind parameters.** `params` reaches SQLite's own parameter binding; the
|
|
229
|
+
values never enter the SQL text, so text holding quotes needs no escaping.
|
|
230
|
+
A sequence (a TypeScript array) fills `?` placeholders in order; a mapping
|
|
231
|
+
(a TypeScript plain object) fills `:name`, `@name` and `$name` placeholders,
|
|
232
|
+
keyed by the name without its prefix. It works for path-tables
|
|
233
|
+
and declared tables alike:
|
|
234
|
+
|
|
235
|
+
::: code-group
|
|
236
|
+
|
|
237
|
+
```python [Python]
|
|
238
|
+
await db.query(
|
|
239
|
+
"SELECT path FROM './*.json' WHERE content ->> 'advice' = :advice",
|
|
240
|
+
{"advice": text},
|
|
241
|
+
)
|
|
242
|
+
await db.query("SELECT * FROM notes WHERE author = ? AND year = ?", ("ann", 2024))
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
```typescript [TypeScript]
|
|
246
|
+
await db.query(
|
|
247
|
+
"SELECT path FROM './*.json' WHERE content ->> 'advice' = :advice",
|
|
248
|
+
{ advice: text },
|
|
249
|
+
);
|
|
250
|
+
await db.query("SELECT * FROM notes WHERE author = ? AND year = ?", ["ann", 2024]);
|
|
251
|
+
// queryOrdered takes params the same way.
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
```rust [Rust]
|
|
255
|
+
use dirsql::{Params, Value};
|
|
256
|
+
use std::collections::HashMap;
|
|
257
|
+
|
|
258
|
+
db.query_with(
|
|
259
|
+
"SELECT path FROM './*.json' WHERE content ->> 'advice' = :advice",
|
|
260
|
+
&Params::Named(HashMap::from([("advice".into(), Value::Text(text))])),
|
|
261
|
+
)?;
|
|
262
|
+
db.query_with(
|
|
263
|
+
"SELECT * FROM notes WHERE author = ?",
|
|
264
|
+
&Params::Positional(vec![Value::Text("ann".into())]),
|
|
265
|
+
)?;
|
|
266
|
+
// query_ordered_with and query_each_with bind the same way;
|
|
267
|
+
// AsyncDirSQL::query_with is the async twin.
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
:::
|
|
271
|
+
|
|
272
|
+
- Values bind as SQLite's native types. Python accepts `None`, `int`
|
|
273
|
+
(`bool` binds as `0`/`1`), `float`, `str`, `bytes` and `bytearray`;
|
|
274
|
+
anything else raises `TypeError` rather than being stringified, and an
|
|
275
|
+
`int` outside the signed 64-bit range raises `OverflowError`. TypeScript
|
|
276
|
+
accepts `null`, `number` (an integral value binds as an INTEGER, any other
|
|
277
|
+
as a REAL, so `1.0` binds as `1`), `bigint`, `boolean` (`0`/`1`), `string`,
|
|
278
|
+
and `Buffer` / `Uint8Array`; anything else, `undefined` included, rejects
|
|
279
|
+
with a `TypeError`, and a `bigint` outside the signed 64-bit range with a
|
|
280
|
+
`RangeError`. Rust binds a `Value`.
|
|
281
|
+
- The params must fit the placeholders exactly, or the query fails with an
|
|
282
|
+
error naming the problem: a wrong count for a sequence, a placeholder name
|
|
283
|
+
the mapping lacks, a mapping key no placeholder uses, or a sequence for
|
|
284
|
+
named placeholders (and a mapping for `?`). Python raises a
|
|
285
|
+
`RuntimeError` for these, and a `TypeError` when `params` is neither a
|
|
286
|
+
sequence nor a mapping (a `str` counts as neither). TypeScript rejects
|
|
287
|
+
with an `Error` for these, and a `TypeError` when `params` is neither an
|
|
288
|
+
array nor a plain object. Rust returns `DbError::Params`.
|
|
289
|
+
- Without `params`, a statement with placeholders fails the same way: a
|
|
290
|
+
placeholder is never left unbound.
|
|
291
|
+
|
|
227
292
|
- **Read-only.** Each statement is classified by SQLite itself
|
|
228
293
|
(`sqlite3_stmt_readonly`); anything classified as a write — `INSERT`,
|
|
229
294
|
`UPDATE`, `DELETE`, `DROP`, `CREATE`, `ALTER`, `VACUUM`, … — is rejected
|
|
@@ -259,11 +324,12 @@ round-trips.
|
|
|
259
324
|
::: code-group
|
|
260
325
|
|
|
261
326
|
```typescript [TypeScript]
|
|
262
|
-
await db.queryOrdered(sql: string) -> { columns: string[]; rows: Record<string, unknown>[] }
|
|
327
|
+
await db.queryOrdered(sql: string, params?: unknown[] | Record<string, unknown> | null) -> { columns: string[]; rows: Record<string, unknown>[] }
|
|
263
328
|
```
|
|
264
329
|
|
|
265
330
|
```rust [Rust]
|
|
266
331
|
db.query_ordered(sql: &str) -> Result<QueryResult> // QueryResult { columns, rows }
|
|
332
|
+
db.query_ordered_with(sql: &str, params: &Params) -> Result<QueryResult>
|
|
267
333
|
```
|
|
268
334
|
|
|
269
335
|
:::
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dirsql",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.143",
|
|
4
4
|
"description": "Ephemeral SQL index over a local directory",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/thekevinscott/dirsql",
|
|
@@ -221,10 +221,10 @@
|
|
|
221
221
|
]
|
|
222
222
|
},
|
|
223
223
|
"optionalDependencies": {
|
|
224
|
-
"@dirsql/lib-linux-x64-gnu": "0.4.
|
|
225
|
-
"@dirsql/lib-linux-arm64-gnu": "0.4.
|
|
226
|
-
"@dirsql/lib-darwin-x64": "0.4.
|
|
227
|
-
"@dirsql/lib-darwin-arm64": "0.4.
|
|
228
|
-
"@dirsql/lib-win32-x64-msvc": "0.4.
|
|
224
|
+
"@dirsql/lib-linux-x64-gnu": "0.4.143",
|
|
225
|
+
"@dirsql/lib-linux-arm64-gnu": "0.4.143",
|
|
226
|
+
"@dirsql/lib-darwin-x64": "0.4.143",
|
|
227
|
+
"@dirsql/lib-darwin-arm64": "0.4.143",
|
|
228
|
+
"@dirsql/lib-win32-x64-msvc": "0.4.143"
|
|
229
229
|
}
|
|
230
230
|
}
|