dirsql 0.4.140 → 0.4.142
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/docs/reference/sdk.md +53 -1
- package/package.json +6 -6
package/docs/reference/sdk.md
CHANGED
|
@@ -208,7 +208,7 @@ 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]
|
|
@@ -218,12 +218,64 @@ await db.query(sql: string) -> Record<string, unknown>[]
|
|
|
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 fills `?` placeholders in order; a mapping fills `:name`
|
|
231
|
+
placeholders, keyed by the name without its prefix. It works for path-tables
|
|
232
|
+
and declared tables alike:
|
|
233
|
+
|
|
234
|
+
::: code-group
|
|
235
|
+
|
|
236
|
+
```python [Python]
|
|
237
|
+
await db.query(
|
|
238
|
+
"SELECT path FROM './*.json' WHERE content ->> 'advice' = :advice",
|
|
239
|
+
{"advice": text},
|
|
240
|
+
)
|
|
241
|
+
await db.query("SELECT * FROM notes WHERE author = ? AND year = ?", ("ann", 2024))
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
```rust [Rust]
|
|
245
|
+
use dirsql::{Params, Value};
|
|
246
|
+
use std::collections::HashMap;
|
|
247
|
+
|
|
248
|
+
db.query_with(
|
|
249
|
+
"SELECT path FROM './*.json' WHERE content ->> 'advice' = :advice",
|
|
250
|
+
&Params::Named(HashMap::from([("advice".into(), Value::Text(text))])),
|
|
251
|
+
)?;
|
|
252
|
+
db.query_with(
|
|
253
|
+
"SELECT * FROM notes WHERE author = ?",
|
|
254
|
+
&Params::Positional(vec![Value::Text("ann".into())]),
|
|
255
|
+
)?;
|
|
256
|
+
// query_ordered_with and query_each_with bind the same way;
|
|
257
|
+
// AsyncDirSQL::query_with is the async twin.
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
:::
|
|
261
|
+
|
|
262
|
+
TypeScript does not take bind parameters yet.
|
|
263
|
+
|
|
264
|
+
- Values bind as SQLite's native types. Python accepts `None`, `int`
|
|
265
|
+
(`bool` binds as `0`/`1`), `float`, `str`, `bytes` and `bytearray`;
|
|
266
|
+
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`.
|
|
269
|
+
- The params must fit the placeholders exactly, or the query fails with an
|
|
270
|
+
error naming the problem: a wrong count for a sequence, a placeholder name
|
|
271
|
+
the mapping lacks, a mapping key no placeholder uses, or a sequence for
|
|
272
|
+
named placeholders (and a mapping for `?`). Python raises a
|
|
273
|
+
`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`.
|
|
276
|
+
- Without `params`, a statement with placeholders fails the same way: a
|
|
277
|
+
placeholder is never left unbound.
|
|
278
|
+
|
|
227
279
|
- **Read-only.** Each statement is classified by SQLite itself
|
|
228
280
|
(`sqlite3_stmt_readonly`); anything classified as a write — `INSERT`,
|
|
229
281
|
`UPDATE`, `DELETE`, `DROP`, `CREATE`, `ALTER`, `VACUUM`, … — is rejected
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dirsql",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.142",
|
|
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.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"
|
|
229
229
|
}
|
|
230
230
|
}
|