@procedures/sqlite 0.3.0 → 0.4.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/CHANGELOG.md +25 -0
- package/README.md +36 -28
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/module.d.ts +13 -3
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +60 -27
- package/dist/module.js.map +1 -1
- package/dist/procedures/db/backup.d.ts +1 -1
- package/dist/procedures/db/backup.js +6 -6
- package/dist/procedures/db/backup.js.map +1 -1
- package/dist/procedures/db/migrate.d.ts +1 -1
- package/dist/procedures/db/migrate.js +8 -8
- package/dist/procedures/db/migrate.js.map +1 -1
- package/dist/procedures/db/schema.d.ts +1 -1
- package/dist/procedures/db/schema.js +3 -3
- package/dist/procedures/db/schema.js.map +1 -1
- package/dist/procedures/db/shared.d.ts +1 -1
- package/dist/procedures/db/shared.js +1 -1
- package/dist/procedures/db/tables.d.ts +1 -1
- package/dist/procedures/db/tables.js +2 -2
- package/dist/procedures/db/tables.js.map +1 -1
- package/dist/procedures/db/transaction.d.ts +1 -1
- package/dist/procedures/db/transaction.js +2 -2
- package/dist/procedures/db/transaction.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/dist/types.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +3 -3
- package/src/module.ts +65 -28
- package/src/procedures/db/backup.ts +6 -6
- package/src/procedures/db/migrate.ts +8 -8
- package/src/procedures/db/schema.ts +3 -3
- package/src/procedures/db/shared.ts +1 -1
- package/src/procedures/db/tables.ts +2 -2
- package/src/procedures/db/transaction.ts +2 -2
- package/src/types.ts +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @procedures/sqlite
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cc3f5f6: The SQLite procedures have the namespace `sqlite`, not the general namespace `db`: `sqlite.query`, `sqlite.execute`, `sqlite.tables`, `sqlite.schema`, `sqlite.transaction`, `sqlite.migrate` and `sqlite.backup`. The `logs.*` procedures keep their names.
|
|
8
|
+
|
|
9
|
+
The old names stay for one release as deprecated aliases (`db.query` and the others). Each alias has the same handler, the same schemas and the same effects. Its description starts with `Deprecated: use sqlite.<name>`, and its metadata has `deprecated: true`. The next release removes the aliases.
|
|
10
|
+
|
|
11
|
+
The description of the `dbPath` field does not show the home folder of the computer any more. It says `~/logs/cli/cli.db`.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [d919678]
|
|
16
|
+
- Updated dependencies [057d69a]
|
|
17
|
+
- Updated dependencies [b2a1a1e]
|
|
18
|
+
- Updated dependencies [057d69a]
|
|
19
|
+
- Updated dependencies [057d69a]
|
|
20
|
+
- Updated dependencies [057d69a]
|
|
21
|
+
- Updated dependencies [057d69a]
|
|
22
|
+
- Updated dependencies [057d69a]
|
|
23
|
+
- Updated dependencies [afd6a19]
|
|
24
|
+
- Updated dependencies [057d69a]
|
|
25
|
+
- Updated dependencies [4e751da]
|
|
26
|
+
- @procedures/client@0.4.0
|
|
27
|
+
|
|
3
28
|
## 0.3.0
|
|
4
29
|
|
|
5
30
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -18,9 +18,17 @@ SQLite database operations via client procedures. Execute queries and store stru
|
|
|
18
18
|
- **A collection storage**: `SqliteStorage` keeps a collection in a SQLite table, with a change log
|
|
19
19
|
|
|
20
20
|
The package has 9 procedures. Its register entry (`import "@procedures/sqlite/register"`) registers them:
|
|
21
|
-
- **Database**: `
|
|
21
|
+
- **Database**: `sqlite.query`, `sqlite.execute`, `sqlite.tables`, `sqlite.schema`, `sqlite.transaction`, `sqlite.migrate`, `sqlite.backup`
|
|
22
22
|
- **Logs**: `logs.store`, `logs.query`
|
|
23
23
|
|
|
24
|
+
### The old names `db.*`
|
|
25
|
+
|
|
26
|
+
In version 0.3.0 and before, the database procedures had the namespace `db`. The general name `db` did not tell the database. Since version 0.4.0, the namespace is `sqlite`.
|
|
27
|
+
|
|
28
|
+
The old names stay for one release as deprecated aliases: `db.query`, `db.execute`, `db.tables`, `db.schema`, `db.transaction`, `db.migrate` and `db.backup`. Each alias has the same handler, the same schemas and the same effects as its new procedure. Its description starts with `Deprecated: use sqlite.<name>`. The next release removes the aliases.
|
|
29
|
+
|
|
30
|
+
The MCP server (`bundle-mcp`) does not expose the aliases. Its tools are `sqlite.query`, `sqlite.execute`, `sqlite.tables` and `sqlite.schema`. The `logs.*` procedures keep their names.
|
|
31
|
+
|
|
24
32
|
## Architecture
|
|
25
33
|
|
|
26
34
|
```mermaid
|
|
@@ -34,7 +42,7 @@ graph TB
|
|
|
34
42
|
Register["register.ts<br/>(Auto-registers procedures)"]
|
|
35
43
|
|
|
36
44
|
subgraph "Procedure Categories"
|
|
37
|
-
DB["Database Procedures<br/>
|
|
45
|
+
DB["Database Procedures<br/>sqlite.query, sqlite.execute, sqlite.tables, sqlite.schema,<br/>sqlite.transaction, sqlite.migrate, sqlite.backup"]
|
|
38
46
|
Logs["Log Procedures<br/>logs.store, logs.query"]
|
|
39
47
|
end
|
|
40
48
|
|
|
@@ -148,7 +156,7 @@ You can override this path in each procedure call:
|
|
|
148
156
|
|
|
149
157
|
```typescript
|
|
150
158
|
await client.exec(
|
|
151
|
-
["
|
|
159
|
+
["sqlite", "query"],
|
|
152
160
|
{
|
|
153
161
|
sql: "SELECT * FROM logs",
|
|
154
162
|
dbPath: "./custom/path/database.db"
|
|
@@ -160,13 +168,13 @@ await client.exec(
|
|
|
160
168
|
|
|
161
169
|
### Database Procedures
|
|
162
170
|
|
|
163
|
-
#### `
|
|
171
|
+
#### `sqlite.query`
|
|
164
172
|
|
|
165
173
|
Execute a SQL SELECT query and return rows.
|
|
166
174
|
|
|
167
175
|
```typescript
|
|
168
176
|
const result = await client.exec(
|
|
169
|
-
["
|
|
177
|
+
["sqlite", "query"],
|
|
170
178
|
{
|
|
171
179
|
sql: "SELECT * FROM logs WHERE level = ? ORDER BY timestamp DESC",
|
|
172
180
|
params: ["error"]
|
|
@@ -197,7 +205,7 @@ interface DbQueryOutput<T = Record<string, unknown>> {
|
|
|
197
205
|
**Example:**
|
|
198
206
|
```typescript
|
|
199
207
|
const result = await client.exec(
|
|
200
|
-
["
|
|
208
|
+
["sqlite", "query"],
|
|
201
209
|
{
|
|
202
210
|
sql: `
|
|
203
211
|
SELECT level, COUNT(*) as count
|
|
@@ -212,13 +220,13 @@ const result = await client.exec(
|
|
|
212
220
|
// result.rows = [{ level: "info", count: 45 }, { level: "error", count: 2 }]
|
|
213
221
|
```
|
|
214
222
|
|
|
215
|
-
#### `
|
|
223
|
+
#### `sqlite.execute`
|
|
216
224
|
|
|
217
225
|
Execute a SQL statement (INSERT, UPDATE, DELETE) and return the number of affected rows.
|
|
218
226
|
|
|
219
227
|
```typescript
|
|
220
228
|
const result = await client.exec(
|
|
221
|
-
["
|
|
229
|
+
["sqlite", "execute"],
|
|
222
230
|
{
|
|
223
231
|
sql: "DELETE FROM logs WHERE timestamp < ?",
|
|
224
232
|
params: ["2024-01-01"]
|
|
@@ -248,7 +256,7 @@ interface DbExecuteOutput {
|
|
|
248
256
|
```typescript
|
|
249
257
|
// INSERT
|
|
250
258
|
await client.exec(
|
|
251
|
-
["
|
|
259
|
+
["sqlite", "execute"],
|
|
252
260
|
{
|
|
253
261
|
sql: "INSERT INTO users (name, email) VALUES (?, ?)",
|
|
254
262
|
params: ["Alice", "alice@example.com"]
|
|
@@ -257,7 +265,7 @@ await client.exec(
|
|
|
257
265
|
|
|
258
266
|
// UPDATE
|
|
259
267
|
await client.exec(
|
|
260
|
-
["
|
|
268
|
+
["sqlite", "execute"],
|
|
261
269
|
{
|
|
262
270
|
sql: "UPDATE users SET active = ? WHERE id = ?",
|
|
263
271
|
params: [true, 123]
|
|
@@ -266,7 +274,7 @@ await client.exec(
|
|
|
266
274
|
|
|
267
275
|
// DELETE
|
|
268
276
|
await client.exec(
|
|
269
|
-
["
|
|
277
|
+
["sqlite", "execute"],
|
|
270
278
|
{
|
|
271
279
|
sql: "DELETE FROM users WHERE active = ?",
|
|
272
280
|
params: [false]
|
|
@@ -274,29 +282,29 @@ await client.exec(
|
|
|
274
282
|
);
|
|
275
283
|
```
|
|
276
284
|
|
|
277
|
-
#### `
|
|
285
|
+
#### `sqlite.tables`
|
|
278
286
|
|
|
279
287
|
The procedure lists the tables and the views of a database, without the internal `sqlite_` tables. Each item has the `name`, the `type` and the `sql` that made it. With `views: false`, it gives only the tables. The procedure only reads. A missing file is an error (`ENOENT`), and the procedure does not make it.
|
|
280
288
|
|
|
281
289
|
```typescript
|
|
282
|
-
const { tables } = await client.exec(["
|
|
290
|
+
const { tables } = await client.exec(["sqlite", "tables"], { dbPath: "./app.db" });
|
|
283
291
|
```
|
|
284
292
|
|
|
285
|
-
#### `
|
|
293
|
+
#### `sqlite.schema`
|
|
286
294
|
|
|
287
295
|
The procedure gives the `columns`, the `indexes` and the `foreignKeys` of a table, or the columns of a view. The name of the table goes to SQLite as a bound value, not as SQL text. The procedure only reads.
|
|
288
296
|
|
|
289
297
|
```typescript
|
|
290
|
-
const schema = await client.exec(["
|
|
298
|
+
const schema = await client.exec(["sqlite", "schema"], { dbPath: "./app.db", table: "users" });
|
|
291
299
|
// schema.columns: [{ name: "id", type: "INTEGER", notNull: false, defaultValue: null, primaryKey: 1 }, ...]
|
|
292
300
|
```
|
|
293
301
|
|
|
294
|
-
#### `
|
|
302
|
+
#### `sqlite.transaction`
|
|
295
303
|
|
|
296
304
|
The procedure puts a list of statements in one transaction. When one statement fails, it rolls back the transaction, and the file stays as it was. The `params` of a statement bind to one statement. Without `params`, one `sql` can hold several statements. A statement that gives rows (`SELECT`, or `RETURNING`) gives its `rows` in its result. The procedure refuses `BEGIN`, `COMMIT`, `ROLLBACK`, `SAVEPOINT` and `RELEASE`, because it controls the transaction itself.
|
|
297
305
|
|
|
298
306
|
```typescript
|
|
299
|
-
const { results, changes } = await client.exec(["
|
|
307
|
+
const { results, changes } = await client.exec(["sqlite", "transaction"], {
|
|
300
308
|
dbPath: "./app.db",
|
|
301
309
|
statements: [
|
|
302
310
|
{ sql: "UPDATE accounts SET balance = balance - ? WHERE id = ?", params: [10, 1] },
|
|
@@ -306,7 +314,7 @@ const { results, changes } = await client.exec(["db", "transaction"], {
|
|
|
306
314
|
});
|
|
307
315
|
```
|
|
308
316
|
|
|
309
|
-
#### `
|
|
317
|
+
#### `sqlite.migrate`
|
|
310
318
|
|
|
311
319
|
The procedure applies the numbered migrations that the database does not have, in the order of their numbers. The migrations come from a `folder` or from a list (`migrations`). In a folder, each migration is a file `<number>_<name>.sql`, for example `001_create_users.sql`. The procedure ignores the files that do not end in `.sql`.
|
|
312
320
|
|
|
@@ -317,20 +325,20 @@ The procedure applies the numbered migrations that the database does not have, i
|
|
|
317
325
|
- A migration must not hold `BEGIN`, `COMMIT` or `ROLLBACK`.
|
|
318
326
|
|
|
319
327
|
```typescript
|
|
320
|
-
const { applied, skipped, version } = await client.exec(["
|
|
328
|
+
const { applied, skipped, version } = await client.exec(["sqlite", "migrate"], {
|
|
321
329
|
dbPath: "./app.db",
|
|
322
330
|
folder: "./migrations",
|
|
323
331
|
});
|
|
324
332
|
```
|
|
325
333
|
|
|
326
|
-
#### `
|
|
334
|
+
#### `sqlite.backup`
|
|
327
335
|
|
|
328
336
|
The procedure copies a database to a new file (`to`). It does not replace a file, and it does not write the source. With `vacuum: true`, it compacts the copy.
|
|
329
337
|
|
|
330
338
|
This package uses SQLite in WebAssembly (sql.js). The database is in the memory of the module. `VACUUM INTO` and the backup API of SQLite write into the file system of the module, not to the disk. Thus the procedure writes the image of the database (its `export()`). It takes the image in the file queue of the database, where no other call of the process changes it. It writes the image to a file next to the target, checks it with `PRAGMA integrity_check`, and then renames it.
|
|
331
339
|
|
|
332
340
|
```typescript
|
|
333
|
-
const { path, bytes } = await client.exec(["
|
|
341
|
+
const { path, bytes } = await client.exec(["sqlite", "backup"], { dbPath: "./app.db", to: "./backups/app-2026-10-16.db" });
|
|
334
342
|
```
|
|
335
343
|
|
|
336
344
|
### Log Procedures
|
|
@@ -526,7 +534,7 @@ The entry `@procedures/sqlite/storage` has the storage alone. The package root e
|
|
|
526
534
|
- A failed file write fails the write. The change stays in memory, and `flush()` or the next write writes it.
|
|
527
535
|
- A storage that only reads does not make the file.
|
|
528
536
|
- The storages of one file in one process share one database. Thus the storages of two tables in one file keep their items.
|
|
529
|
-
- Another process, and the procedures `
|
|
537
|
+
- Another process, and the procedures `sqlite.query` and `sqlite.execute`, do not share this database. Do not write the file from them while a storage has it open.
|
|
530
538
|
|
|
531
539
|
### The durable local copy of `HybridStorage`
|
|
532
540
|
|
|
@@ -556,7 +564,7 @@ const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
|
|
|
556
564
|
|
|
557
565
|
// Create a table
|
|
558
566
|
await client.exec(
|
|
559
|
-
["
|
|
567
|
+
["sqlite", "execute"],
|
|
560
568
|
{
|
|
561
569
|
sql: `
|
|
562
570
|
CREATE TABLE IF NOT EXISTS users (
|
|
@@ -573,7 +581,7 @@ await client.exec(
|
|
|
573
581
|
|
|
574
582
|
// Insert data
|
|
575
583
|
await client.exec(
|
|
576
|
-
["
|
|
584
|
+
["sqlite", "execute"],
|
|
577
585
|
{
|
|
578
586
|
sql: "INSERT INTO users (name, email) VALUES (?, ?)",
|
|
579
587
|
params: ["Alice Johnson", "alice@example.com"],
|
|
@@ -583,7 +591,7 @@ await client.exec(
|
|
|
583
591
|
|
|
584
592
|
// Query data
|
|
585
593
|
const result = await client.exec(
|
|
586
|
-
["
|
|
594
|
+
["sqlite", "query"],
|
|
587
595
|
{
|
|
588
596
|
sql: "SELECT * FROM users WHERE active = ? ORDER BY created_at DESC",
|
|
589
597
|
params: [1],
|
|
@@ -747,7 +755,7 @@ interface User {
|
|
|
747
755
|
}
|
|
748
756
|
|
|
749
757
|
const result = await client.call<DbQueryOutput<User>>(
|
|
750
|
-
["
|
|
758
|
+
["sqlite", "query"],
|
|
751
759
|
{
|
|
752
760
|
sql: "SELECT * FROM users WHERE active = ?",
|
|
753
761
|
params: [true],
|
|
@@ -827,10 +835,10 @@ export type {
|
|
|
827
835
|
client-sqlite/
|
|
828
836
|
├── src/
|
|
829
837
|
│ ├── types.ts # Type definitions
|
|
830
|
-
│ ├── module.ts # The procedures as data, and the
|
|
838
|
+
│ ├── module.ts # The procedures as data, and the sqlite.query, sqlite.execute and logs.* handlers
|
|
831
839
|
│ ├── register.ts # The ./register entry: registers the module
|
|
832
840
|
│ ├── storage.ts # SqliteStorage, the collection storage (the ./storage entry)
|
|
833
|
-
│ ├── procedures/db/ #
|
|
841
|
+
│ ├── procedures/db/ # sqlite.tables, sqlite.schema, sqlite.transaction, sqlite.migrate, sqlite.backup
|
|
834
842
|
│ └── index.ts # Main entry point
|
|
835
843
|
├── dist/ # Compiled output
|
|
836
844
|
├── package.json
|