chord-postgres 0.0.0-stage → 0.1.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 +19 -0
- package/LICENSE +21 -0
- package/README.md +271 -3
- package/dist/catalog.d.ts +25 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +71 -0
- package/dist/catalog.js.map +1 -0
- package/dist/database.d.ts +76 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +468 -0
- package/dist/database.js.map +1 -0
- package/dist/dialect.d.ts +73 -0
- package/dist/dialect.d.ts.map +1 -0
- package/dist/dialect.js +671 -0
- package/dist/dialect.js.map +1 -0
- package/dist/errors.d.ts +31 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +45 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/pi-durable.d.ts +47 -0
- package/dist/pi-durable.d.ts.map +1 -0
- package/dist/pi-durable.js +97 -0
- package/dist/pi-durable.js.map +1 -0
- package/dist/queue.d.ts +17 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +37 -0
- package/dist/queue.js.map +1 -0
- package/docs/dialect.md +103 -0
- package/docs/port-chord-1.7.md +83 -0
- package/docs/port-chord-template.md +64 -0
- package/package.json +95 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.js","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AAiCA,uHAAuH;AACvH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,GAAG,CAAQ;IAEpB,YAAY,GAAW,EAAE,MAAc;QACrC,KAAK,CAAC,mBAAmB,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QACvD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;QACjC,IAAI,CAAC,G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AAG,EAAE,IAAI,CAAC,GAAG,CAAA;AAC1C,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The errors this package adds to the ones Postgres and chord raise.
|
|
3
|
+
*
|
|
4
|
+
* Every one of them is a failure the caller must not retry inside the same database object: a lost connection latches
|
|
5
|
+
* (see `database.ts`), and an unsupported statement is a bug in the translation that retrying cannot fix.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The connection to Postgres was lost, and this database object will not use another one.
|
|
9
|
+
*
|
|
10
|
+
* Failing closed is deliberate. A commit whose connection died may or may not have committed; the store's in-memory
|
|
11
|
+
* id allocator only learns the new `next_id` from a reply that never arrived, so continuing on a fresh connection
|
|
12
|
+
* could hand out an id the lost transaction already used. The parent error is kept as `cause`.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ConnectionLostError extends Error {
|
|
15
|
+
constructor(schema: string, cause: unknown);
|
|
16
|
+
}
|
|
17
|
+
/** The database object was closed, or a transaction handle used after its callback settled. */
|
|
18
|
+
export declare class ClosedError extends Error {
|
|
19
|
+
constructor(message: string);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The database holds a store written by a newer version of this adapter.
|
|
23
|
+
*
|
|
24
|
+
* Refusing is the point: a newer store may have a column an older adapter would silently drop on the next write.
|
|
25
|
+
*/
|
|
26
|
+
export declare class SchemaTooNewError extends Error {
|
|
27
|
+
readonly found: number;
|
|
28
|
+
readonly supported: number;
|
|
29
|
+
constructor(found: number, supported: number);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAMzC;CACF;AAED,+FAA+F;AAC/F,qBAAa,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAE1B,YAAY,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAO3C;CACF"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The errors this package adds to the ones Postgres and chord raise.
|
|
3
|
+
*
|
|
4
|
+
* Every one of them is a failure the caller must not retry inside the same database object: a lost connection latches
|
|
5
|
+
* (see `database.ts`), and an unsupported statement is a bug in the translation that retrying cannot fix.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The connection to Postgres was lost, and this database object will not use another one.
|
|
9
|
+
*
|
|
10
|
+
* Failing closed is deliberate. A commit whose connection died may or may not have committed; the store's in-memory
|
|
11
|
+
* id allocator only learns the new `next_id` from a reply that never arrived, so continuing on a fresh connection
|
|
12
|
+
* could hand out an id the lost transaction already used. The parent error is kept as `cause`.
|
|
13
|
+
*/
|
|
14
|
+
export class ConnectionLostError extends Error {
|
|
15
|
+
constructor(schema, cause) {
|
|
16
|
+
const detail = cause instanceof Error ? cause.message : String(cause);
|
|
17
|
+
super(`chord-postgres: the connection to the "${schema}" schema was lost and will not be replaced (${detail})`, {
|
|
18
|
+
cause,
|
|
19
|
+
});
|
|
20
|
+
this.name = 'ConnectionLostError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** The database object was closed, or a transaction handle used after its callback settled. */
|
|
24
|
+
export class ClosedError extends Error {
|
|
25
|
+
constructor(message) {
|
|
26
|
+
super(`chord-postgres: ${message}`);
|
|
27
|
+
this.name = 'ClosedError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The database holds a store written by a newer version of this adapter.
|
|
32
|
+
*
|
|
33
|
+
* Refusing is the point: a newer store may have a column an older adapter would silently drop on the next write.
|
|
34
|
+
*/
|
|
35
|
+
export class SchemaTooNewError extends Error {
|
|
36
|
+
found;
|
|
37
|
+
supported;
|
|
38
|
+
constructor(found, supported) {
|
|
39
|
+
super(`chord-postgres: the database holds adapter schema version ${String(found)}, newer than this version supports (${String(supported)}); upgrade chord-postgres`);
|
|
40
|
+
this.name = 'SchemaTooNewError';
|
|
41
|
+
this.found = found;
|
|
42
|
+
this.supported = supported;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,MAAc,EAAE,KAAc;QACxC,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACrE,KAAK,CAAC,0CAA0C,MAAM,+CAA+C,MAAM,GAAG,EAAE;YAC9G,KAAK;SACN,CAAC,CAAA;QACF,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF;AAED,+FAA+F;AAC/F,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,mBAAmB,OAAO,EAAE,CAAC,CAAA;QACnC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAC3B,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,KAAK,CAAQ;IACb,SAAS,CAAQ;IAE1B,YAAY,KAAa,EAAE,SAAiB;QAC1C,KAAK,CACH,6DAA6D,MAAM,CAAC,KAAK,CAAC,uCAAuC,MAAM,CAAC,SAAS,CAAC,2BAA2B,CAC9J,CAAA;QACD,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chord-postgres`: a PostgreSQL backend for chord's store, and through it for pi-durable.
|
|
3
|
+
*
|
|
4
|
+
* chord's store runs on a `SqliteDatabase` — five async SQL methods plus `transaction` and `close` — which is how the
|
|
5
|
+
* Cloudflare Durable Object backend is plugged in too. This package supplies that interface over node-postgres, so
|
|
6
|
+
* chord apps get their declared tables, documents, outbox and export/import on Postgres, and pi-durable gets a
|
|
7
|
+
* `Storage` (`chord-postgres/pi-durable`) without a line of its own code changing.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { postgresBackend, openPostgresStore } from 'chord-postgres'
|
|
11
|
+
* import { BACKGROUND_CONTEXT } from '@earendil-works/chord/context'
|
|
12
|
+
*
|
|
13
|
+
* const store = await openPostgresStore({ connection: process.env.DATABASE_URL }, BACKGROUND_CONTEXT)
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import type { Backend } from '@earendil-works/chord';
|
|
17
|
+
import type { Context } from '@earendil-works/chord/context';
|
|
18
|
+
import { openStore } from '@earendil-works/chord';
|
|
19
|
+
import type { PostgresDatabaseOptions } from './database.js';
|
|
20
|
+
export { DEFAULT_SCHEMA, DEFAULT_STATEMENT_TIMEOUT_MS, PostgresDatabase, postgresDatabase } from './database.js';
|
|
21
|
+
export type { PostgresDatabaseOptions } from './database.js';
|
|
22
|
+
export { CONSTRUCTS, UnsupportedSqlError } from './dialect.js';
|
|
23
|
+
export type { ColumnKind, TableInfo } from './dialect.js';
|
|
24
|
+
export { ClosedError, ConnectionLostError, SchemaTooNewError } from './errors.js';
|
|
25
|
+
export { isConnectionLoss } from './database.js';
|
|
26
|
+
/** What {@link openPostgresStore} takes: the database's options and the store's. */
|
|
27
|
+
export interface PostgresStoreOptions extends PostgresDatabaseOptions {
|
|
28
|
+
/** Turns the store's outbox on (`true`) or off (`false`); omitted, the persisted setting stays. */
|
|
29
|
+
readonly outbox?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** The store `openStore` returns, named through the function so this package follows chord's own type. */
|
|
32
|
+
export type PostgresStore = Awaited<ReturnType<typeof openStore>>;
|
|
33
|
+
/**
|
|
34
|
+
* A chord backend over Postgres, ready for `openStore` or `importStore`.
|
|
35
|
+
*
|
|
36
|
+
* `openStore` (and `importStore`) close the backend they are given, so a store opened this way owns its pool: there is
|
|
37
|
+
* nothing else to close.
|
|
38
|
+
*/
|
|
39
|
+
export declare function postgresBackend(options: PostgresDatabaseOptions): Promise<Backend>;
|
|
40
|
+
/**
|
|
41
|
+
* Opens a chord store on Postgres: the store's own schema, then chord's `openStore` on top of it.
|
|
42
|
+
*
|
|
43
|
+
* `close` the store (not this package) when the app is done; that closes the backend and with it the pool.
|
|
44
|
+
*/
|
|
45
|
+
export declare function openPostgresStore(options: PostgresStoreOptions, context: Context): Promise<PostgresStore>;
|
|
46
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAG5D,OAAO,EAAE,cAAc,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChH,YAAY,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAC9D,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,oFAAoF;AACpF,MAAM,WAAW,oBAAqB,SAAQ,uBAAuB;IACnE,mGAAmG;IACnG,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED,0GAA0G;AAC1G,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAA;AAEjE;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC,CAExF;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,aAAa,CAAC,CAaxB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { sqliteBackend } from '@earendil-works/chord';
|
|
2
|
+
import { openStore } from '@earendil-works/chord';
|
|
3
|
+
import { postgresDatabase } from './database.js';
|
|
4
|
+
export { DEFAULT_SCHEMA, DEFAULT_STATEMENT_TIMEOUT_MS, PostgresDatabase, postgresDatabase } from './database.js';
|
|
5
|
+
export { CONSTRUCTS, UnsupportedSqlError } from './dialect.js';
|
|
6
|
+
export { ClosedError, ConnectionLostError, SchemaTooNewError } from './errors.js';
|
|
7
|
+
export { isConnectionLoss } from './database.js';
|
|
8
|
+
/**
|
|
9
|
+
* A chord backend over Postgres, ready for `openStore` or `importStore`.
|
|
10
|
+
*
|
|
11
|
+
* `openStore` (and `importStore`) close the backend they are given, so a store opened this way owns its pool: there is
|
|
12
|
+
* nothing else to close.
|
|
13
|
+
*/
|
|
14
|
+
export async function postgresBackend(options) {
|
|
15
|
+
return sqliteBackend(await postgresDatabase(options));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Opens a chord store on Postgres: the store's own schema, then chord's `openStore` on top of it.
|
|
19
|
+
*
|
|
20
|
+
* `close` the store (not this package) when the app is done; that closes the backend and with it the pool.
|
|
21
|
+
*/
|
|
22
|
+
export async function openPostgresStore(options, context) {
|
|
23
|
+
const database = await postgresDatabase(options);
|
|
24
|
+
const backend = sqliteBackend(database);
|
|
25
|
+
try {
|
|
26
|
+
return options.outbox === undefined
|
|
27
|
+
? await openStore(backend, context)
|
|
28
|
+
: await openStore(backend, context, { outbox: options.outbox });
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
// `openStore` closes the backend on a failure itself (chord's rule 12); closing twice is idempotent, and a pool
|
|
32
|
+
// left open would keep the process alive.
|
|
33
|
+
await database.close().catch(() => undefined);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAGjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,OAAO,EAAE,cAAc,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhH,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAE9D,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAWhD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAgC;IACpE,OAAO,aAAa,CAAC,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAA;AACvD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAA6B,EAC7B,OAAgB;IAEhB,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAChD,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;IACvC,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,MAAM,KAAK,SAAS;YACjC,CAAC,CAAC,MAAM,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC;YACnC,CAAC,CAAC,MAAM,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IACnE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,gHAAgH;QAChH,0CAA0C;QAC1C,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;QAC7C,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chord-postgres/pi-durable`: pi-durable's `Storage` on Postgres, in one call.
|
|
3
|
+
*
|
|
4
|
+
* pi-durable already ships exactly this shape for SQLite — `StoreStorage`, its `Storage` over a chord store — so the
|
|
5
|
+
* only thing missing was a chord backend on Postgres. This module opens the store, claims the owner's tables in it and
|
|
6
|
+
* hands back a `Storage`:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { Harness } from '@earendil-works/pi-durable'
|
|
10
|
+
* import { postgresStorage } from 'chord-postgres/pi-durable'
|
|
11
|
+
*
|
|
12
|
+
* const storage = await postgresStorage({ connection: process.env.DATABASE_URL, owner: 'demo' }, context)
|
|
13
|
+
* const harness = await Harness.open(storage, options, context)
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* One difference from SQLite is deliberate. `StoreStorage.close` leaves the store open, because the store is the app's;
|
|
17
|
+
* here this call opened the store for the storage alone, so the storage's `close` closes it too — and with it the pool.
|
|
18
|
+
* A host that wants several ownered storages on one store opens the store itself and calls
|
|
19
|
+
* `StoreStorage.open(store, owner, context)`.
|
|
20
|
+
*/
|
|
21
|
+
import type { Context } from '@earendil-works/chord/context';
|
|
22
|
+
import type { Storage } from '@earendil-works/pi-durable';
|
|
23
|
+
import type { PostgresStore, PostgresStoreOptions } from './index.js';
|
|
24
|
+
/** What {@link postgresStorage} takes: the store's options and the owner name pi-durable's tables live under. */
|
|
25
|
+
export interface PostgresStorageOptions extends PostgresStoreOptions {
|
|
26
|
+
/**
|
|
27
|
+
* The owner name pi-durable's tables live under, as `"<owner>:<table>"`. pi-durable's own rule for it is
|
|
28
|
+
* `[a-z0-9@/._~-]+`. The longest name pi-durable declares is `<owner>:entries:conversation`, so an owner of more than
|
|
29
|
+
* 38 characters exceeds Postgres' 63-byte identifier limit and is refused when the tables are declared.
|
|
30
|
+
*/
|
|
31
|
+
readonly owner: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A pi-durable `Storage` that also exposes the chord store it runs on, for a host that wants chord's tables beside
|
|
35
|
+
* pi-durable's records.
|
|
36
|
+
*/
|
|
37
|
+
export interface PostgresStorage extends Storage {
|
|
38
|
+
/** The chord store the records live in. Closing the storage closes it. */
|
|
39
|
+
readonly store: PostgresStore;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Opens pi-durable's `Storage` on Postgres: a chord store in the schema, then pi-durable's `StoreStorage` over it.
|
|
43
|
+
*
|
|
44
|
+
* `close(context)` closes the store as well as the storage, because this call opened it.
|
|
45
|
+
*/
|
|
46
|
+
export declare function postgresStorage(options: PostgresStorageOptions, context: Context): Promise<PostgresStorage>;
|
|
47
|
+
//# sourceMappingURL=pi-durable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-durable.d.ts","sourceRoot":"","sources":["../src/pi-durable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AA4BzD,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAUrE,iHAAiH;AACjH,MAAM,WAAW,sBAAuB,SAAQ,oBAAoB;IAClE;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,OAAO;IAC9C,0EAA0E;IAC1E,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;CAC9B;AA0ID;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,eAAe,CAAC,CAU1B"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { StoreStorage as ChordStoreStorage } from '@earendil-works/pi-durable/storage/store';
|
|
2
|
+
import { openPostgresStore } from './index.js';
|
|
3
|
+
/**
|
|
4
|
+
* pi-durable's `Storage` over the `Storage` it wraps, with a `close` that also closes the store this call opened.
|
|
5
|
+
*
|
|
6
|
+
* The delegation is written out rather than proxied: pi-durable's `Storage` gained a breaking change in a patch release
|
|
7
|
+
* once already, and a wrapper that fails to compile is the cheapest possible warning that it moved again.
|
|
8
|
+
*/
|
|
9
|
+
class StoreStorageStorage {
|
|
10
|
+
#storage;
|
|
11
|
+
store;
|
|
12
|
+
constructor(storage, store) {
|
|
13
|
+
this.#storage = storage;
|
|
14
|
+
this.store = store;
|
|
15
|
+
}
|
|
16
|
+
commit(batches, receive, context) {
|
|
17
|
+
return this.#storage.commit(batches, receive, context);
|
|
18
|
+
}
|
|
19
|
+
publishing(publish, context) {
|
|
20
|
+
this.#storage.publishing(publish, context);
|
|
21
|
+
}
|
|
22
|
+
mintId() {
|
|
23
|
+
return this.#storage.mintId();
|
|
24
|
+
}
|
|
25
|
+
conversation(id, context) {
|
|
26
|
+
return this.#storage.conversation(id, context);
|
|
27
|
+
}
|
|
28
|
+
scanConversations(query, limit, cursor, context) {
|
|
29
|
+
return this.#storage.scanConversations(query, limit, cursor, context);
|
|
30
|
+
}
|
|
31
|
+
entry(first, second, third) {
|
|
32
|
+
// pi-durable's `Storage` declares two call shapes; `StoreStorage` dispatches them by arity itself, and so does this.
|
|
33
|
+
return third === undefined
|
|
34
|
+
? this.#storage.entry(first, second)
|
|
35
|
+
: this.#storage.entry(first, second, third);
|
|
36
|
+
}
|
|
37
|
+
findLatestHeadMarker(conversationId, atOrBeforeEntryId, context) {
|
|
38
|
+
return this.#storage.findLatestHeadMarker(conversationId, atOrBeforeEntryId, context);
|
|
39
|
+
}
|
|
40
|
+
scanEntries(query, limit, cursor, context) {
|
|
41
|
+
return this.#storage.scanEntries(query, limit, cursor, context);
|
|
42
|
+
}
|
|
43
|
+
task(id, context) {
|
|
44
|
+
return this.#storage.task(id, context);
|
|
45
|
+
}
|
|
46
|
+
scanTasks(query, limit, cursor, context) {
|
|
47
|
+
return this.#storage.scanTasks(query, limit, cursor, context);
|
|
48
|
+
}
|
|
49
|
+
submission(id, context) {
|
|
50
|
+
return this.#storage.submission(id, context);
|
|
51
|
+
}
|
|
52
|
+
scanSubmissions(query, limit, cursor, context) {
|
|
53
|
+
return this.#storage.scanSubmissions(query, limit, cursor, context);
|
|
54
|
+
}
|
|
55
|
+
submissionByRequest(conversationId, requestId, context) {
|
|
56
|
+
return this.#storage.submissionByRequest(conversationId, requestId, context);
|
|
57
|
+
}
|
|
58
|
+
findDocument(address, at, context) {
|
|
59
|
+
return this.#storage.findDocument(address, at, context);
|
|
60
|
+
}
|
|
61
|
+
document(id, at, context) {
|
|
62
|
+
return this.#storage.document(id, at, context);
|
|
63
|
+
}
|
|
64
|
+
scanDocuments(query, limit, cursor, context) {
|
|
65
|
+
return this.#storage.scanDocuments(query, limit, cursor, context);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Releases the owner's claims and then closes the store (and the pool), which `StoreStorage` alone would leave open.
|
|
69
|
+
* Both steps run even when the first throws, so a failed close never leaves the process holding a pool.
|
|
70
|
+
*/
|
|
71
|
+
async close(context) {
|
|
72
|
+
try {
|
|
73
|
+
await this.#storage.close(context);
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
await this.store.close(context);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Opens pi-durable's `Storage` on Postgres: a chord store in the schema, then pi-durable's `StoreStorage` over it.
|
|
82
|
+
*
|
|
83
|
+
* `close(context)` closes the store as well as the storage, because this call opened it.
|
|
84
|
+
*/
|
|
85
|
+
export async function postgresStorage(options, context) {
|
|
86
|
+
const { owner, ...storeOptions } = options;
|
|
87
|
+
const store = await openPostgresStore(storeOptions, context);
|
|
88
|
+
try {
|
|
89
|
+
const storage = await ChordStoreStorage.open(store, owner, context);
|
|
90
|
+
return new StoreStorageStorage(storage, store);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
await store.close(context).catch(() => undefined);
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=pi-durable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-durable.js","sourceRoot":"","sources":["../src/pi-durable.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,YAAY,IAAI,iBA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AACH,CAAC"}
|
package/dist/queue.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs operations in call order.
|
|
3
|
+
*
|
|
4
|
+
* chord's `SqliteDatabase` contract (`sqlite/database.d.ts`) says an adapter *must* queue unrelated operations and
|
|
5
|
+
* other transactions until a transaction finishes, because the store hands raw reads out without a transaction and
|
|
6
|
+
* advances its in-memory `lastSeq` only after `COMMIT`. SQLite serialises everything on one connection; a Postgres
|
|
7
|
+
* adapter has to do it itself. A transaction takes the queue for its whole callback (`hold`), which is the same
|
|
8
|
+
* mechanism chord's Cloudflare adapter uses (`sqlite/cloudflare.ts`).
|
|
9
|
+
*/
|
|
10
|
+
export declare class SerialQueue {
|
|
11
|
+
#private;
|
|
12
|
+
/** Runs `operation` now when the queue is idle, else after everything queued before it. */
|
|
13
|
+
run<T>(operation: () => Promise<T>): Promise<T>;
|
|
14
|
+
/** Runs `operation` after everything queued before it, and queues everything after it behind it. */
|
|
15
|
+
hold<T>(operation: () => Promise<T>): Promise<T>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,WAAW;;IAItB,2FAA2F;IAC3F,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAO9C;IAED,oGAAoG;IACpG,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE/C;CAaF"}
|
package/dist/queue.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs operations in call order.
|
|
3
|
+
*
|
|
4
|
+
* chord's `SqliteDatabase` contract (`sqlite/database.d.ts`) says an adapter *must* queue unrelated operations and
|
|
5
|
+
* other transactions until a transaction finishes, because the store hands raw reads out without a transaction and
|
|
6
|
+
* advances its in-memory `lastSeq` only after `COMMIT`. SQLite serialises everything on one connection; a Postgres
|
|
7
|
+
* adapter has to do it itself. A transaction takes the queue for its whole callback (`hold`), which is the same
|
|
8
|
+
* mechanism chord's Cloudflare adapter uses (`sqlite/cloudflare.ts`).
|
|
9
|
+
*/
|
|
10
|
+
export class SerialQueue {
|
|
11
|
+
#tail = Promise.resolve();
|
|
12
|
+
#pending = 0;
|
|
13
|
+
/** Runs `operation` now when the queue is idle, else after everything queued before it. */
|
|
14
|
+
run(operation) {
|
|
15
|
+
if (this.#pending > 0)
|
|
16
|
+
return this.#enqueue(operation);
|
|
17
|
+
try {
|
|
18
|
+
return Promise.resolve(operation());
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return Promise.reject(error);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Runs `operation` after everything queued before it, and queues everything after it behind it. */
|
|
25
|
+
hold(operation) {
|
|
26
|
+
return this.#enqueue(operation);
|
|
27
|
+
}
|
|
28
|
+
#enqueue(operation) {
|
|
29
|
+
this.#pending += 1;
|
|
30
|
+
const result = this.#tail.then(operation).finally(() => {
|
|
31
|
+
this.#pending -= 1;
|
|
32
|
+
});
|
|
33
|
+
this.#tail = result.then(() => undefined, () => undefined);
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,WAAW;IACtB,KAAK,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAA;IACxC,QAAQ,GAAG,CAAC,CAAA;IAEZ,2FAA2F;IAC3F,GAAG,CAAI,SAA2B;QAChC,IAAI,IAAI,CAAC,QAAQ,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QACtD,IAAI,CAAC;YACH,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAA;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAC9B,CAAC;IACH,CAAC;IAED,oGAAoG;IACpG,IAAI,CAAI,SAA2B;QACjC,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;IACjC,CAAC;IAED,QAAQ,CAAI,SAA2B;QACrC,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAA;QAClB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;YACrD,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAA;QACpB,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CACtB,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAChB,CAAA;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|
package/docs/dialect.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# The SQL dialect layer
|
|
2
|
+
|
|
3
|
+
chord's store generates SQLite SQL. This package runs that SQL on Postgres, so every construct it emits has to be
|
|
4
|
+
translated — or refused. This page is the complete list, and [`src/dialect.ts`](../src/dialect.ts) is the code:
|
|
5
|
+
`CONSTRUCTS` there is the machine-readable copy of the table below, and `src/dialect.test.ts` has a case per construct
|
|
6
|
+
plus the loud failures.
|
|
7
|
+
|
|
8
|
+
Four rules govern the module:
|
|
9
|
+
|
|
10
|
+
1. **A translator, not a parser.** The statement is tokenized, so quoted identifiers and string literals are never
|
|
11
|
+
rewritten. Every rule matches a *statement shape* chord is known to emit, on tokens.
|
|
12
|
+
2. **Fail loudly.** Anything that survives the rules and is still SQLite-specific (`?`, `STRICT`, `WITHOUT ROWID`,
|
|
13
|
+
`json_each`, `AUTOINCREMENT`, a `PRAGMA`) throws `UnsupportedSqlError` with the statement in the message. Guessing is
|
|
14
|
+
the one failure mode a translation layer cannot afford: sending mis-translated SQL writes the wrong row instead of
|
|
15
|
+
failing a test.
|
|
16
|
+
3. **Type names are matched case-sensitively.** `TEXT`, `INTEGER` and `REAL` are the spellings chord's generator emits,
|
|
17
|
+
so an upper-case word is chord's and a lower-case one — hand-written DDL passed through `exec`, for instance — is left
|
|
18
|
+
as the caller wrote it. Without that rule `text COLLATE "C"` would become `text COLLATE "C" COLLATE "C"`.
|
|
19
|
+
4. **One statement, one round trip.** No rule costs a second statement. What a transaction costs is in the README's
|
|
20
|
+
"What it costs".
|
|
21
|
+
|
|
22
|
+
## The constructs
|
|
23
|
+
|
|
24
|
+
Where the `where` column cites a chord file, it is chord 1.7.0's `dist/`.
|
|
25
|
+
|
|
26
|
+
| # | SQLite construct | Becomes | Where chord emits it |
|
|
27
|
+
| --- | --- | --- | --- |
|
|
28
|
+
| 1 | `?` positional placeholders | `$1`, `$2`, … numbered left to right, counted outside literals and quoted identifiers | every statement |
|
|
29
|
+
| 2 | `INSERT OR REPLACE INTO t (c…) VALUES (…)` | `INSERT … ON CONFLICT (key) DO UPDATE SET c = EXCLUDED.c`; the key is read from `pg_catalog` once per table | `store/sql.js` (`putSql`, every `put`), `store/catalog.js` |
|
|
30
|
+
| 3 | `INSERT OR IGNORE INTO t …` | `INSERT … ON CONFLICT DO NOTHING` | `sqlite/migrations.js` |
|
|
31
|
+
| 4 | `x IN (SELECT value FROM json_each(?))` | `x = ANY(?::<column type>[])`, bound as a JavaScript array | `store/sql.js` (`whereSql`, `inArray`) |
|
|
32
|
+
| 5 | scalar `max(a, b)` / `min(a, b)` | `CASE WHEN a IS NULL OR b IS NULL THEN NULL ELSE GREATEST(a, b) END` (SQLite's NULL rule) | `store/sql.js` (`exprSql`) |
|
|
33
|
+
| 6 | `CROSS JOIN t AS p ON …` | `INNER JOIN t AS p ON …` — Postgres allows no join condition on `CROSS JOIN` | `store/read-plan.js` (`fromClause`, a joined column set) |
|
|
34
|
+
| 7 | `TEXT` columns | `text COLLATE "C"` — chord compares text by code point, which is UTF-8 byte order. Matched in upper case only, so hand-written DDL in the same `exec` keeps its own spelling | `store/sql.js` (`columnSql`), `store/schema.js` |
|
|
35
|
+
| 8 | `INTEGER` columns and keys | `bigint` (chord's `int` is a safe integer; the ±2^53−1 `CHECK` is kept) | `store/sql.js`, `store/schema.js` |
|
|
36
|
+
| 9 | `REAL` columns | `double precision` — Postgres `REAL` is `float4` and would lose digits | `store/sql.js` (`num` columns) |
|
|
37
|
+
| 10 | `json(...)` columns | `text`, unchanged: chord stores serialized JSON and parses it on read | `store/sql.js`, `store/rows.js` |
|
|
38
|
+
| 11 | `bool` columns | `bigint` with `CHECK (c IN (0, 1))` — chord reads `value === 1`, never a Postgres `boolean` | `store/sql.js`, `store/rows.js` (`decodeScalar`) |
|
|
39
|
+
| 12 | `STRICT`, `WITHOUT ROWID` | dropped | `store/sql.js` (`createTableSql`), `store/schema.js`, `sqlite/migrations.js` |
|
|
40
|
+
| 13 | `PRAGMA encoding` | `SELECT 'UTF-8' AS encoding` | `store/schema.js` (`applyStoreSchema`) |
|
|
41
|
+
| 14 | `pragma_encoding` (a table-valued function in a `FROM`) | `(SELECT 'UTF-8'::text AS encoding)` | `store/schema.js` (`CURRENT_META`) |
|
|
42
|
+
| 15 | `sqlite_master` | a compatibility view over `pg_catalog`, created in the adapter's schema | `store/import.js` (the "the backend holds a store already" check) |
|
|
43
|
+
| 16 | `count(*) AS count`, `max(id)`, every other `int8` | a JavaScript number — a `pg` type parser converts `int8` per query; outside the safe range it throws | `store/read-plan.js` (`count`), pi-durable's `SELECT max("id")` |
|
|
44
|
+
| 17 | `BEGIN IMMEDIATE`, the writer lock | `BEGIN` + `pg_advisory_xact_lock` on the schema, in one round trip | chord's own SQLite adapters (`sqlite/node.js`); the store assumes one writer per session |
|
|
45
|
+
| 18 | DDL inside a transaction | unchanged — Postgres DDL is transactional, so `evolveTable` commits or rolls back with its commit | `store/table-writes.js` |
|
|
46
|
+
|
|
47
|
+
## Constructs that need no translation
|
|
48
|
+
|
|
49
|
+
Listed because "it works" is a claim worth checking, and because a future chord release might stop making it true:
|
|
50
|
+
|
|
51
|
+
| Shape | Where |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| `SELECT … WHERE … ORDER BY "col" ASC, "id" ASC LIMIT $n` | `store/sql.js` (`TableSql.select`), `store/read-plan.js` |
|
|
54
|
+
| row-value comparison `("a", "b") > ($1, $2)` | `store/sql.js` (`select` after a cursor), `store/export.js` |
|
|
55
|
+
| `EXISTS (SELECT 1 FROM "t" AS e0 WHERE e0."x" = t."y")` | `store/read-plan.js` (`existsSql`) |
|
|
56
|
+
| `SELECT 1 AS found … LIMIT 1` (the probe) | `store/read-plan.js`, `store/host-data.js` |
|
|
57
|
+
| `SELECT count(*) AS count …` | `store/read-plan.js` (`count`) |
|
|
58
|
+
| partial indexes (`CREATE INDEX … WHERE retired_at IS NULL`) | `store/schema.js` |
|
|
59
|
+
| `substr(x, 1, ?)`, `||`, `coalesce`, `CASE WHEN`, `+`, `-` | `store/sql.js` (`exprSql`) |
|
|
60
|
+
| `ALTER TABLE … RENAME/ADD/DROP COLUMN` | `store/table-writes.js` |
|
|
61
|
+
| `DELETE … WHERE`, `UPDATE … SET … WHERE` with `runCounted` (= `rowCount`) | `store/sql.js`, `store/engine.js` |
|
|
62
|
+
| `SELECT DISTINCT owner FROM … WHERE host = $1` | `store/host-data.js` |
|
|
63
|
+
| `TRIM`ped string literals (`'base'`, `'delta'`, `'none'`) | `store/engine.js`, `store/schema.js` |
|
|
64
|
+
|
|
65
|
+
## Constructs that are refused
|
|
66
|
+
|
|
67
|
+
Each of these is a deliberate `UnsupportedSqlError`, with the statement in the message:
|
|
68
|
+
|
|
69
|
+
| Refused | Why |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| a `?` the translator did not number, or a placeholder/binding count mismatch | binding the wrong value to the wrong column is worse than failing |
|
|
72
|
+
| any `PRAGMA` but `encoding` | no Postgres meaning |
|
|
73
|
+
| `IN (…)` that is neither a literal list in a table definition nor chord's `json_each` idiom | a sub-select this adapter has not verified |
|
|
74
|
+
| `IN (0, 1)` **outside** a table definition | the only literal `IN` chord emits is a `bool` `CHECK` |
|
|
75
|
+
| an `INSERT OR REPLACE` that omits the table's key column, or names a table the catalogue cannot describe | the conflict target would be a guess |
|
|
76
|
+
| an `inArray` on a column whose type the adapter does not know, or whose binding is not a JSON array of that type | the array cast would be a guess |
|
|
77
|
+
| an identifier longer than 63 bytes, in DDL | Postgres truncates it silently, which merges two tables |
|
|
78
|
+
| `STRICT`, `WITHOUT`, `json_each`, `AUTOINCREMENT` outside a statement the rules rewrote | a construct added by a future chord release |
|
|
79
|
+
| an unterminated quoted value, or a character the tokenizer does not know | it cannot be translated safely |
|
|
80
|
+
|
|
81
|
+
## The two places the difference is not textual
|
|
82
|
+
|
|
83
|
+
**A failed statement aborts its transaction.** SQLite leaves the transaction usable after an error; Postgres does not,
|
|
84
|
+
and every later statement fails with `current transaction is aborted` until a rollback. chord's store tolerates exactly
|
|
85
|
+
one failure — `store/schema.js`'s `currentMeta` reads its metadata through a statement that joins `pragma_encoding`, and
|
|
86
|
+
`catch`es the error to mean "this database holds no store". During `importStore` that probe is the transaction's *first*
|
|
87
|
+
statement, so letting it fail would fail the import. The adapter therefore recognises the probe (it is the only statement
|
|
88
|
+
that mentions `pragma_encoding`) and answers it from the catalogue: if `chord_store_schema` or `chord_meta` is not a
|
|
89
|
+
table in the schema, it returns `SELECT 1 WHERE false` — no rows, which is what chord's `catch` produces. Everything else
|
|
90
|
+
keeps Postgres' semantics, because silently swallowing a failed statement is how a store loses a write.
|
|
91
|
+
|
|
92
|
+
**The writer lock.** SQLite's `BEGIN IMMEDIATE` takes the write lock at the start of a transaction. Postgres has no
|
|
93
|
+
equivalent, so `transaction()` takes `pg_advisory_xact_lock(hashtextextended('chord-postgres:<schema>', 0))` right after
|
|
94
|
+
`BEGIN` — in the same round trip, as `BEGIN; SELECT pg_advisory_xact_lock(…)`. The lock is held until `COMMIT`, which is
|
|
95
|
+
exactly the guarantee the store's check-then-write pattern needs, and it is per schema rather than per table, so two
|
|
96
|
+
stores over one schema serialise rather than deadlock.
|
|
97
|
+
|
|
98
|
+
## Adding a construct
|
|
99
|
+
|
|
100
|
+
1. Add the rule to `translate`'s pipeline in `src/dialect.ts`, with the statement shape it matches.
|
|
101
|
+
2. Add its entry to `CONSTRUCTS` (the doc table above mirrors it, and a test asserts there is one entry per construct).
|
|
102
|
+
3. Add a case to `src/dialect.test.ts` — one that would fail if the rule misfired, not just one that runs it.
|
|
103
|
+
4. Add anything the store now generates to `test/store.test.ts` or `test/conformance.test.ts`, whichever reaches it.
|