@zukhruf/sqlite-federation 0.6.16 → 0.8.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 +15 -14
- package/dist/federation.d.ts +1 -1
- package/dist/federation.d.ts.map +1 -1
- package/dist/federation.js +2 -2
- package/dist/federation.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -20,18 +20,18 @@ The host gives `locate`. A statement names each database as a schema.
|
|
|
20
20
|
import { mkdtempDisposable } from 'node:fs/promises';
|
|
21
21
|
import { tmpdir } from 'node:os';
|
|
22
22
|
import { join } from 'node:path';
|
|
23
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
24
23
|
|
|
25
24
|
import { Federation } from '@zukhruf/sqlite-federation';
|
|
25
|
+
import { open } from '@zukhruf/sqlite-open';
|
|
26
26
|
|
|
27
27
|
await using scratch = await mkdtempDisposable(join(tmpdir(), 'federation-'));
|
|
28
28
|
const messagesPath = join(scratch.path, 'messages.sqlite');
|
|
29
29
|
const contactsPath = join(scratch.path, 'contacts.sqlite');
|
|
30
30
|
{
|
|
31
|
-
using messages =
|
|
31
|
+
using messages = open(messagesPath);
|
|
32
32
|
messages.exec(`CREATE TABLE messages (handle TEXT, text TEXT);
|
|
33
33
|
INSERT INTO messages VALUES ('+962790000000', 'See you at 6');`);
|
|
34
|
-
using contacts =
|
|
34
|
+
using contacts = open(contactsPath);
|
|
35
35
|
contacts.exec(`CREATE TABLE contacts (phone TEXT, name TEXT);
|
|
36
36
|
INSERT INTO contacts VALUES ('+962790000000', 'Sara');`);
|
|
37
37
|
}
|
|
@@ -80,7 +80,7 @@ const result = federation.query('SELECT * FROM conversations');
|
|
|
80
80
|
|
|
81
81
|
Qualified tables and PRAGMAs discover additional databases through `locate`. Both `PRAGMA contacts.table_info(contacts)` and `SELECT * FROM pragma_table_info('contacts', 'contacts')` locate Contacts, including when the schema is a bound parameter in a tagged query. Quoted schema names such as `"call-history"` work too. Every attachment made for the statement is detached afterwards, including on failure; `main` and temporary views remain on the connection. The additional databases count toward the attachment limit.
|
|
82
82
|
|
|
83
|
-
The constructor accepts Node's `timeout` option for waiting on a writer's lock, in milliseconds.
|
|
83
|
+
The constructor accepts Node's `timeout` option for waiting on a writer's lock, in milliseconds. Without it, the handle waits 5000 ms, the busy timeout of `@zukhruf/sqlite-open`. Hosts that need crash recovery perform it before supplying the paths, including inside `locate` for a named primary or additional database; Federation opens those files read-only.
|
|
84
84
|
|
|
85
85
|
## Read a primary database
|
|
86
86
|
|
|
@@ -108,16 +108,17 @@ const result = database.query(
|
|
|
108
108
|
|
|
109
109
|
## Errors
|
|
110
110
|
|
|
111
|
-
| Error | When
|
|
112
|
-
| -------------------------------------- |
|
|
113
|
-
| `TooManyDatabasesError` | A statement names more databases than the limit. `names` has at least one name more than the limit. The message tells you to split the statement.
|
|
114
|
-
| `Unknown main database <name>` | The constructor cannot locate the named primary database.
|
|
115
|
-
| `no such table: <name>.<table>` | The error of SQLite, when `locate` returns `undefined` for the name, or when the database does not have the table.
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
|
|
|
119
|
-
|
|
|
120
|
-
| `
|
|
111
|
+
| Error | When |
|
|
112
|
+
| -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
113
|
+
| `TooManyDatabasesError` | A statement names more databases than the limit. `names` has at least one name more than the limit. The message tells you to split the statement. |
|
|
114
|
+
| `Unknown main database <name>` | The constructor cannot locate the named primary database. |
|
|
115
|
+
| `no such table: <name>.<table>` | The error of SQLite, when `locate` returns `undefined` for the name, or when the database does not have the table. |
|
|
116
|
+
| `UnavailableError` | The constructor cannot open the primary database: the file is missing, or the system denies access. `path` is the path. `cause` is the error of SQLite. It is the class of `@zukhruf/sqlite-open`. |
|
|
117
|
+
| `unable to open database file` | The error of SQLite, when `locate` returns a path with no file for a database that a statement attaches. |
|
|
118
|
+
| `attempt to write a readonly database` | The error of SQLite, when a statement writes. |
|
|
119
|
+
| The error of `locate` | The constructor or statement fails with that error. The databases that the statement attached before are detached. |
|
|
120
|
+
| `unknown database <name>` | The error of SQLite, when a PRAGMA names a database that `locate` cannot find. Quoting follows the statement or the table-valued PRAGMA argument. |
|
|
121
|
+
| `Run one SQL statement at a time` | A raw query contains a second statement. |
|
|
121
122
|
|
|
122
123
|
## The same concepts in other systems
|
|
123
124
|
|
package/dist/federation.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { DatabaseSyncOptions, SQLOutputValue, SQLTagStore } from 'node:sqlite';
|
|
2
2
|
export type Query = Pick<SQLTagStore, 'all' | 'get'>;
|
|
3
3
|
export type QueryResult = {
|
|
4
4
|
readonly columns: readonly string[];
|
package/dist/federation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"federation.d.ts","sourceRoot":"","sources":["../src/federation.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"federation.d.ts","sourceRoot":"","sources":["../src/federation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,mBAAmB,EACnB,cAAc,EACd,WAAW,EACZ,MAAM,aAAa,CAAC;AAQrB,MAAM,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,KAAK,GAAG,KAAK,CAAC,CAAC;AAGrD,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;CACpE,CAAC;AAIF,MAAM,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAE1D,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC,GAAG;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAClD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAKF,qBAAa,UAAW,YAAW,UAAU;;IAC3C,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;gBAIR,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,EAAE,iBAAiB;IAuB3D,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAOvB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW;IA2D/B,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAGzB"}
|
package/dist/federation.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { open } from '@zukhruf/sqlite-open';
|
|
2
2
|
import { TooManyDatabasesError } from "./too-many-databases-error.js";
|
|
3
3
|
// One read-only handle over main and every database the host can locate, past
|
|
4
4
|
// the limit on how many one SQLite connection attaches at once. Main stays
|
|
@@ -15,7 +15,7 @@ export class Federation {
|
|
|
15
15
|
throw new Error(`Unknown main database ${main.name}`);
|
|
16
16
|
main = path;
|
|
17
17
|
}
|
|
18
|
-
this.#connection =
|
|
18
|
+
this.#connection = open(main, {
|
|
19
19
|
...options,
|
|
20
20
|
readOnly: true,
|
|
21
21
|
});
|
package/dist/federation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"federation.js","sourceRoot":"","sources":["../src/federation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"federation.js","sourceRoot":"","sources":["../src/federation.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,+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C,CAAC,CAAC;IAClE,IAAI,KAAK,KAAK,SAAS;QACrB,OAAO,2BAA2B,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC9D,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,IAAI,KAAK,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7C,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,GAAG;QACjD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,GAAG,KAAK,EAAE,KAAK,CAAC,CAAC;IAC7D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,MAAM,CAAC,IAAY;IAC1B,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;AAC3C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { Federation, type FederationOptions, type Locate, type Query, type QueryResult, } from './federation.ts';
|
|
2
2
|
export { TooManyDatabasesError } from './too-many-databases-error.ts';
|
|
3
|
+
export { UnavailableError } from '@zukhruf/sqlite-open';
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,WAAW,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,WAAW,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,GAKX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,GAKX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/sqlite-federation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "One read-only handle over many SQLite databases. Each statement attaches the databases it names and detaches them when it ends. So a host can keep more databases than the SQLite attach limit, and one statement can read 10 plus the primary database.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -40,7 +40,10 @@
|
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@zukhruf/sqlite-open": "^0.8.0"
|
|
45
|
+
},
|
|
43
46
|
"devDependencies": {
|
|
44
|
-
"@zukhruf/testing": "^0.
|
|
47
|
+
"@zukhruf/testing": "^0.8.0"
|
|
45
48
|
}
|
|
46
49
|
}
|