@plurnk/plurnk-execs-sqlite 1.16.5 → 1.18.0
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 +10 -11
- package/dist/Sqlite.js +4 -4
- package/dist/Sqlite.js.map +1 -1
- package/docs/sqlite.md +7 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,15 +12,15 @@ A `@plurnk/plurnk-execs-*` sibling built on the [plurnk-execs](https://github.co
|
|
|
12
12
|
|
|
13
13
|
## Database target
|
|
14
14
|
|
|
15
|
-
The
|
|
15
|
+
The execution's target slot is the database file; with no target it defaults to an ephemeral in-memory db:
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
````sqlite
|
|
18
|
+
SELECT 1 AS value;
|
|
19
|
+
````
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
SELECT
|
|
23
|
-
|
|
21
|
+
````sqlite (./app.db)
|
|
22
|
+
SELECT name FROM sqlite_master WHERE type = 'table';
|
|
23
|
+
````
|
|
24
24
|
|
|
25
25
|
With no target, a fresh `:memory:` database exists for that operation only.
|
|
26
26
|
State does not persist across EXECs. Pass a file path for persistence.
|
|
@@ -29,10 +29,9 @@ State does not persist across EXECs. Pass a file path for persistence.
|
|
|
29
29
|
|
|
30
30
|
With no target, `:memory:` is a scratch calculator over ad-hoc tables — build one inline with `VALUES` and aggregate, no schema or file needed:
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
### EXEC0 (sqlite)
|
|
32
|
+
````sqlite
|
|
34
33
|
WITH t(item,qty,price) AS (VALUES ('a',3,2),('b',1,5)) SELECT sum(qty*price) AS total, sum(qty*price)*1.0/sum(qty) AS avg_price FROM t;
|
|
35
|
-
|
|
34
|
+
````
|
|
36
35
|
|
|
37
36
|
**Use floats to avoid integer truncation.** SQLite integer division truncates — `11/4` → `2`. Multiply by `1.0` (or `CAST(x AS REAL)`) to force real division: `11*1.0/4` → `2.75`. Any division over integer columns needs this, or the result is silently floored.
|
|
38
37
|
|
|
@@ -44,7 +43,7 @@ Writes to the `results` channel as `application/json`, ready for the jsonpath bo
|
|
|
44
43
|
- **Mutations** (INSERT/UPDATE/DELETE/DDL) → `{ changes, lastInsertRowid }`.
|
|
45
44
|
|
|
46
45
|
The query/mutation split is decided by the prepared statement's `columns()`,
|
|
47
|
-
never by parsing the SQL. One statement per
|
|
46
|
+
never by parsing the SQL. One statement per fence. Errors return RFC 9457
|
|
48
47
|
Problems in the terminal operation result.
|
|
49
48
|
|
|
50
49
|
## Configuration
|
package/dist/Sqlite.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isAbsolute, resolve } from "node:path";
|
|
|
2
2
|
import { DatabaseSync } from "node:sqlite";
|
|
3
3
|
import { BaseExecutor, ErrorDetail, renderJsonResult, Results } from "@plurnk/plurnk-execs";
|
|
4
4
|
const MEMORY = ":memory:";
|
|
5
|
-
// Resolve the
|
|
5
|
+
// Resolve the execution's (target) slot to a db path: a relative target resolves
|
|
6
6
|
// against cwd ({§executor-sinks}); null — or an explicit
|
|
7
7
|
// `:memory:` — means no file target → an ephemeral in-memory db.
|
|
8
8
|
const dbPath = (cwd, target) => {
|
|
@@ -17,12 +17,12 @@ const jsonReplacer = (_key, value) => (typeof value === "bigint" ? value.toStrin
|
|
|
17
17
|
// post-statement tail holds real SQL or just trivia.
|
|
18
18
|
const stripComments = (sql) => sql.replace(/--[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
19
19
|
// In-process SQLite executor (a logical runtime, not subprocess). Runs one SQL
|
|
20
|
-
// statement via node:sqlite against the
|
|
20
|
+
// statement via node:sqlite against the target db — defaulting to an
|
|
21
21
|
// ephemeral `:memory:` when no target is given — and writes the result to the
|
|
22
22
|
// `results` channel as application/json, ready for the jsonpath body-matcher.
|
|
23
23
|
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
24
|
+
// sqlite fence, no target: SELECT 1; → :memory: (ephemeral)
|
|
25
|
+
// sqlite fence, target ./app.db: SELECT * FROM users; → ./app.db (persistent)
|
|
26
26
|
//
|
|
27
27
|
// Row-returning statements (SELECT, RETURNING, PRAGMA) write an array of row
|
|
28
28
|
// objects; mutations write `{ changes, lastInsertRowid }`. The query/mutation
|
package/dist/Sqlite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sqlite.js","sourceRoot":"","sources":["../src/Sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,YAAY,EAAsB,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG5F,MAAM,MAAM,GAAG,UAAU,CAAC;AAE1B,
|
|
1
|
+
{"version":3,"file":"Sqlite.js","sourceRoot":"","sources":["../src/Sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,YAAY,EAAsB,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG5F,MAAM,MAAM,GAAG,UAAU,CAAC;AAE1B,iFAAiF;AACjF,yDAAyD;AACzD,iEAAiE;AACjE,MAAM,MAAM,GAAG,CAAC,GAAkB,EAAE,MAAqB,EAAU,EAAE;IACjE,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IACxD,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;AAC/E,CAAC,CAAC;AAEF,0EAA0E;AAC1E,sCAA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AE,MAAM,EAAE,GAAG,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,OAAO,IAAI,CACP,cAAc,EACd,2CAA2C,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,EAAE,EACnF,GAAG,EACH;gBACI,KAAK,EAAE,WAAW;aACrB,CACJ,CAAC;QACN,CAAC;gBAAS,CAAC;YACP,EAAE,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IACL,CAAC;CACJ"}
|
package/docs/sqlite.md
CHANGED
|
@@ -3,18 +3,19 @@
|
|
|
3
3
|
Runs **one SQL statement** in-process via `node:sqlite` and writes the result to the `results` channel as `application/json` — ready for a jsonpath body-matcher.
|
|
4
4
|
|
|
5
5
|
One statement per operation is enforced. A multi-statement script fails with
|
|
6
|
-
`
|
|
6
|
+
`sqlite-multi-statement` (400) and names the rejected tail; partial execution
|
|
7
7
|
never passes as success. Trailing semicolons and comments are allowed.
|
|
8
8
|
Dot-commands such as `.tables` and `.schema` belong to the sqlite3 shell rather
|
|
9
9
|
than SQL. Use their SQL equivalents, such as querying `sqlite_master`.
|
|
10
10
|
|
|
11
11
|
## Database target
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
`sqlite (./app.db)` with a SQL body runs against the file `./app.db` (created if absent),
|
|
14
14
|
a persistent host-mutating database that requires proposal review. With no
|
|
15
15
|
target, it runs against a fresh `:memory:` database that is gone when the
|
|
16
|
-
operation finishes and bypasses proposal review. A directory is not a database
|
|
17
|
-
|
|
16
|
+
operation finishes and bypasses proposal review. A directory is not a database.
|
|
17
|
+
Use `[{"cwd": "./data"}]` on the heading to set the base for a relative database path;
|
|
18
|
+
it does not change whether the operation uses a file or memory.
|
|
18
19
|
|
|
19
20
|
## Query vs mutation
|
|
20
21
|
|
|
@@ -24,5 +25,5 @@ The result shape is decided by the statement's columns, never by parsing the SQL
|
|
|
24
25
|
- **Mutation** (INSERT / UPDATE / DELETE / CREATE) → `{ changes, lastInsertRowid }`.
|
|
25
26
|
|
|
26
27
|
Large integers come back stringified (JSON cannot hold a bigint). Failures close
|
|
27
|
-
`results` as `errored` with an RFC 9457 Problem: invalid authored SQL is 400,
|
|
28
|
-
|
|
28
|
+
`results` as `errored` with an RFC 9457 Problem: invalid authored SQL is 400, and
|
|
29
|
+
runtime/open failures are 500.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plurnk/plurnk-execs-sqlite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.0",
|
|
4
4
|
"description": "SQLite runtime executor for plurnk-service's exec scheme — runs the sqlite runtime tag in-process via node:sqlite, results as application/json.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plurnk",
|
|
@@ -77,6 +77,6 @@
|
|
|
77
77
|
"prepublishOnly": "npm audit --audit-level=moderate && npm test"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"@plurnk/plurnk-execs": "^1.
|
|
80
|
+
"@plurnk/plurnk-execs": "^1.18.0"
|
|
81
81
|
}
|
|
82
82
|
}
|