@archildata/sqlite 0.0.29 → 0.0.30-next.20261201223110

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.
Files changed (2) hide show
  1. package/README.md +28 -32
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,48 +1,44 @@
1
1
  # @archildata/sqlite
2
2
 
3
- Run SQLite statements against an Archil disk through serverless execution.
3
+ Serverless SQLite databases on [Archil](https://archil.com) disks. Each query runs where
4
+ the database file lives, through Archil's serverless execution.
5
+
6
+ Full documentation is at [docs.archil.com](https://docs.archil.com/integrations/sqlite).
7
+
8
+ ## Install
9
+
10
+ ```sh
11
+ npm install disk @archildata/sqlite
12
+ ```
13
+
14
+ Queries run through `disk`'s default client, so set `ARCHIL_API_KEY` and `ARCHIL_REGION`,
15
+ or call `configure` from `disk` first.
16
+
17
+ ## Usage
4
18
 
5
19
  ```ts
20
+ import * as archil from "disk";
6
21
  import { createDatabase, getDatabase } from "@archildata/sqlite";
7
22
 
23
+ const disk = await archil.getDisk(process.env.ARCHIL_DISK_ID!);
8
24
  const db = await createDatabase(disk, "apps/app-1/main.sqlite");
9
25
 
10
- const userName = "archil";
26
+ await db.write`CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, name TEXT)`.run();
11
27
 
28
+ const name = "archil";
12
29
  const user = await db.write<{ id: number; name: string }>`
13
- INSERT INTO users(name) VALUES (${userName})
14
- RETURNING id, name
30
+ INSERT INTO users(name) VALUES (${name}) RETURNING id, name
15
31
  `.get();
32
+ const users = await db.read`SELECT * FROM users`.all();
16
33
 
17
- const users = await db.read`SELECT * FROM users WHERE name = ${userName}`.all();
18
-
19
- const update = await db.write`
20
- UPDATE users SET last_seen_at = ${new Date().toISOString()} WHERE name = ${userName}
21
- `.run();
22
-
23
- await db.transaction([
24
- db.write`INSERT INTO audit_log(user_name, action) VALUES (${userName}, ${"login"})`.run(),
25
- db.read`SELECT * FROM users WHERE name = ${userName}`.get(),
26
- ]);
27
-
34
+ // Open a database that already exists
28
35
  const existing = await getDatabase(disk, "apps/app-1/main.sqlite");
29
36
  ```
30
37
 
31
- Each database is addressed by its file path on the Archil disk. `createDatabase`
32
- creates the parent directory and initializes the file with a queued writable
33
- root mount. `getDatabase` assumes that the
34
- database file already exists; missing databases surface as query-time errors.
35
-
36
- `read` and `write` create query objects. Use `get()` for one row, `all()` for all
37
- rows, and `run()` for SQLite's write result (`changes` and `lastInsertRowid`).
38
- The `read` or `write` tag controls the remote mount mode, so use `write` for
39
- mutating statements, including statements with `RETURNING`.
40
-
41
- `transaction([...])` runs query executions from `get()`, `all()`, and `run()` in
42
- a single remote SQLite transaction. If every execution came from `read`, the
43
- database is opened read-only; otherwise it is opened read-write.
38
+ A database is a file path on the disk. `createDatabase` creates the file and its parent
39
+ directories, and `getDatabase` opens a file that already exists.
44
40
 
45
- The package always uses `disk`'s top-level multi-disk `exec({ disks, command })`
46
- for remote execution, mounting the whole disk at `/mnt/archil/disk`. Writable
47
- query executions request a short mount queue; nested database paths checkout the
48
- database's parent directory so SQLite can safely create journal/WAL sidecars.
41
+ Use `read` for queries and `write` for statements that change data, including ones with
42
+ `RETURNING`. Each query ends with `get()` for one row, `all()` for every row, or `run()` for
43
+ the write result (`changes` and `lastInsertRowid`). `db.transaction([...])` runs several
44
+ queries in one transaction.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archildata/sqlite",
3
- "version": "0.0.29",
3
+ "version": "0.0.30-next.20261201223110",
4
4
  "description": "serverless SQLite databases on Archil disks",
5
5
  "keywords": [
6
6
  "archil",
@@ -29,11 +29,11 @@
29
29
  "LICENSE"
30
30
  ],
31
31
  "peerDependencies": {
32
- "disk": "1.16.0"
32
+ "disk": "1.16.1-next.20261201223110"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/node": "^20.19.33",
36
- "disk": "1.16.0",
36
+ "disk": "1.16.1-next.20261201223110",
37
37
  "tsdown": "^0.22.3",
38
38
  "typescript": "^6.0.3",
39
39
  "vitest": "^4.1.9"