@effectstream/db 0.100.15 → 0.100.17
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 +23 -18
- package/migrations/system-version.ts +9 -6
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -5,6 +5,11 @@ connection pool, ships every pgtyped-generated SQL query the runtime
|
|
|
5
5
|
needs, owns the snapshot loop, and provides a mutex needed for safe
|
|
6
6
|
single-threaded PgLite access.
|
|
7
7
|
|
|
8
|
+
- Pooled Postgres client plus every pgtyped query the runtime needs.
|
|
9
|
+
- Snapshot loop (`runSnapshotLoop`) and `acquireDBMutex` / `releaseDBMutex` for PgLite.
|
|
10
|
+
- Subpath scripts for in-memory PgLite, migrations, and version checks.
|
|
11
|
+
- `getConnection()` is the dominant entry point, ~31 call sites across the repo.
|
|
12
|
+
|
|
8
13
|
## Install
|
|
9
14
|
|
|
10
15
|
```bash
|
|
@@ -44,7 +49,7 @@ try {
|
|
|
44
49
|
|
|
45
50
|
For PgLite (in-memory) the package ships `./start-pglite`,
|
|
46
51
|
`./apply-migrations`, `./db-wait`, `./pgtyped-update`, `./version` as
|
|
47
|
-
small executable subpaths
|
|
52
|
+
small executable subpaths - used directly by the orchestrator.
|
|
48
53
|
|
|
49
54
|
> **PgLite caveat:** PgLite is single-writer. Wrap PgLite-bound code in
|
|
50
55
|
> `acquireDBMutex(name)` / `releaseDBMutex(name)` so concurrent generators
|
|
@@ -62,35 +67,35 @@ can rejoin without re-syncing from genesis.
|
|
|
62
67
|
|
|
63
68
|
Connection management (heavily used):
|
|
64
69
|
|
|
65
|
-
- `getConnection(creds?)
|
|
66
|
-
- `acquireDBMutex(name, priority?)`
|
|
67
|
-
- `waitUntilFree()`
|
|
68
|
-
- `getPersistentConnection(creds)`
|
|
70
|
+
- `getConnection(creds?)`: pooled `Pool` singleton. Dominant entry point (~31 call sites across the repo).
|
|
71
|
+
- `acquireDBMutex(name, priority?)` and `releaseDBMutex(name)` coordinate PgLite access; ~7 call sites each.
|
|
72
|
+
- `waitUntilFree()` - companion to the mutex.
|
|
73
|
+
- `getPersistentConnection(creds)` returns a non-pooled `Client` for long-lived listeners.
|
|
69
74
|
|
|
70
75
|
Queries (pgtyped-generated, shipped under one umbrella):
|
|
71
76
|
|
|
72
|
-
- `getBlockHeights`, `getBlockByHash`, `blockHeightDone`, `saveLastBlock`, `getLatestProcessedBlockHeight
|
|
73
|
-
- `getAchievementProgress`, `setAchievementProgress
|
|
77
|
+
- Block bookkeeping: `getBlockHeights`, `getBlockByHash`, `blockHeightDone`, `saveLastBlock`, `getLatestProcessedBlockHeight`.
|
|
78
|
+
- Achievements: `getAchievementProgress`, `setAchievementProgress`.
|
|
74
79
|
- Re-exports of `*.queries.ts` for statistics, nonces, rollup inputs, accounts, events, sync protocol pages, primitives, system, tables.
|
|
75
80
|
|
|
76
81
|
Snapshots:
|
|
77
82
|
|
|
78
|
-
- `runSnapshotLoop`
|
|
79
|
-
- `createSnapshot
|
|
80
|
-
- `SnapshotConfig`, `SnapshotRetentionConfig
|
|
83
|
+
- `runSnapshotLoop` - periodic `pg_dump` of synced state.
|
|
84
|
+
- `createSnapshot`: single-shot snapshot helper.
|
|
85
|
+
- `SnapshotConfig`, `SnapshotRetentionConfig`: config types.
|
|
81
86
|
|
|
82
87
|
Dynamic table / event helpers:
|
|
83
88
|
|
|
84
|
-
- `createDynamicTables`
|
|
85
|
-
- `createIndexesForEvents
|
|
89
|
+
- `createDynamicTables` registers tables a primitive wants to own.
|
|
90
|
+
- `createIndexesForEvents` creates pgtyped indexes for app events; `registerEventTypes` records each event's topic/name in the database.
|
|
86
91
|
|
|
87
92
|
Subpath entry points (executable scripts):
|
|
88
93
|
|
|
89
|
-
- `@effectstream/db/start-pglite
|
|
90
|
-
- `@effectstream/db/apply-migrations`
|
|
91
|
-
- `@effectstream/db/db-wait
|
|
92
|
-
- `@effectstream/db/pgtyped-update
|
|
93
|
-
- `@effectstream/db/version`
|
|
94
|
+
- `@effectstream/db/start-pglite`: boot a PgLite instance.
|
|
95
|
+
- `@effectstream/db/apply-migrations` - apply SQL migrations against the active DB.
|
|
96
|
+
- `@effectstream/db/db-wait`: block until the DB accepts a connection.
|
|
97
|
+
- `@effectstream/db/pgtyped-update`: regenerate pgtyped types.
|
|
98
|
+
- `@effectstream/db/version` - print schema version.
|
|
94
99
|
|
|
95
100
|
## Examples
|
|
96
101
|
|
|
@@ -100,4 +105,4 @@ Subpath entry points (executable scripts):
|
|
|
100
105
|
## Links
|
|
101
106
|
|
|
102
107
|
- Docs: https://effectstream.github.io/docs/packages/node/db
|
|
103
|
-
- Source: https://github.com/
|
|
108
|
+
- Source: https://github.com/effectstream/effectstream/tree/main/packages/node-sdk/db
|
|
@@ -104,12 +104,15 @@ export function* getLastBlockHeight(
|
|
|
104
104
|
dbConn: Client,
|
|
105
105
|
): Operation<number> {
|
|
106
106
|
yield* acquireDBMutex("get-last-block-height");
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
.
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
try {
|
|
108
|
+
if (versionInfo.is_empty) return 0;
|
|
109
|
+
const rows = yield* until(
|
|
110
|
+
getLatestProcessedBlockHeight.run(undefined, dbConn),
|
|
111
|
+
);
|
|
112
|
+
return rows[0]?.block_height ?? 0;
|
|
113
|
+
} finally {
|
|
114
|
+
releaseDBMutex("get-last-block-height");
|
|
115
|
+
}
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
export function* getVersionInfo(dbConn: Client): Operation<VersionInfo> {
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectstream/db",
|
|
3
|
-
"version": "0.100.
|
|
3
|
+
"version": "0.100.17",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://effectstream.github.io/docs/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/
|
|
8
|
+
"url": "https://github.com/effectstream/effectstream",
|
|
9
9
|
"directory": "packages/node-sdk/db"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/
|
|
12
|
+
"url": "https://github.com/effectstream/effectstream/issues"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
".": "./src/mod.ts",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"./version": "./migrations/system-version.ts"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@effectstream/coroutine": "0.100.
|
|
25
|
-
"@effectstream/log": "0.100.
|
|
26
|
-
"@effectstream/runtime": "0.100.
|
|
27
|
-
"@effectstream/sync": "0.100.
|
|
28
|
-
"@effectstream/utils": "0.100.
|
|
24
|
+
"@effectstream/coroutine": "0.100.17",
|
|
25
|
+
"@effectstream/log": "0.100.17",
|
|
26
|
+
"@effectstream/runtime": "0.100.17",
|
|
27
|
+
"@effectstream/sync": "0.100.17",
|
|
28
|
+
"@effectstream/utils": "0.100.17",
|
|
29
29
|
"@electric-sql/pglite": "^0.3.14",
|
|
30
30
|
"@pgtyped/runtime": "2.4.2",
|
|
31
31
|
"@pgtyped/parser": "2.4.2",
|