dirsql 0.4.142 → 0.4.144

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 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";
@@ -212,7 +212,7 @@ 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
 
@@ -227,8 +227,9 @@ Executes a SQL query and returns rows keyed by column name.
227
227
 
228
228
  **Bind parameters.** `params` reaches SQLite's own parameter binding; the
229
229
  values never enter the SQL text, so text holding quotes needs no escaping.
230
- A sequence fills `?` placeholders in order; a mapping fills `:name`
231
- placeholders, keyed by the name without its prefix. It works for path-tables
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
232
233
  and declared tables alike:
233
234
 
234
235
  ::: code-group
@@ -241,6 +242,15 @@ await db.query(
241
242
  await db.query("SELECT * FROM notes WHERE author = ? AND year = ?", ("ann", 2024))
242
243
  ```
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
+
244
254
  ```rust [Rust]
245
255
  use dirsql::{Params, Value};
246
256
  use std::collections::HashMap;
@@ -259,20 +269,23 @@ db.query_with(
259
269
 
260
270
  :::
261
271
 
262
- TypeScript does not take bind parameters yet.
263
-
264
272
  - Values bind as SQLite's native types. Python accepts `None`, `int`
265
273
  (`bool` binds as `0`/`1`), `float`, `str`, `bytes` and `bytearray`;
266
274
  anything else raises `TypeError` rather than being stringified, and an
267
- `int` outside the signed 64-bit range raises `OverflowError`. Rust binds a
268
- `Value`.
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`.
269
281
  - The params must fit the placeholders exactly, or the query fails with an
270
282
  error naming the problem: a wrong count for a sequence, a placeholder name
271
283
  the mapping lacks, a mapping key no placeholder uses, or a sequence for
272
284
  named placeholders (and a mapping for `?`). Python raises a
273
285
  `RuntimeError` for these, and a `TypeError` when `params` is neither a
274
- sequence nor a mapping (a `str` counts as neither). Rust returns
275
- `DbError::Params`.
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`.
276
289
  - Without `params`, a statement with placeholders fails the same way: a
277
290
  placeholder is never left unbound.
278
291
 
@@ -311,11 +324,12 @@ round-trips.
311
324
  ::: code-group
312
325
 
313
326
  ```typescript [TypeScript]
314
- 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>[] }
315
328
  ```
316
329
 
317
330
  ```rust [Rust]
318
331
  db.query_ordered(sql: &str) -> Result<QueryResult> // QueryResult { columns, rows }
332
+ db.query_ordered_with(sql: &str, params: &Params) -> Result<QueryResult>
319
333
  ```
320
334
 
321
335
  :::
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirsql",
3
- "version": "0.4.142",
3
+ "version": "0.4.144",
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.142",
225
- "@dirsql/lib-linux-arm64-gnu": "0.4.142",
226
- "@dirsql/lib-darwin-x64": "0.4.142",
227
- "@dirsql/lib-darwin-arm64": "0.4.142",
228
- "@dirsql/lib-win32-x64-msvc": "0.4.142"
224
+ "@dirsql/lib-linux-x64-gnu": "0.4.144",
225
+ "@dirsql/lib-linux-arm64-gnu": "0.4.144",
226
+ "@dirsql/lib-darwin-x64": "0.4.144",
227
+ "@dirsql/lib-darwin-arm64": "0.4.144",
228
+ "@dirsql/lib-win32-x64-msvc": "0.4.144"
229
229
  }
230
230
  }