Repository navigation
Extract shared AbstractPostgresPersistenceAdapter for core (TODO A4) - #67
Merged
Merged
Conversation
Same pattern as the digest/journal extractions: the ~40 pure-SQL core persistence methods (instances, charts, ongoing activities, deferred events, external ids) are written once against $N positional placeholders in an abstract base that stays generic over ConnectionType, so core-pg and core-pglite keep their own connection type and withTransaction signature unchanged. Each driver now only implements runQuery plus its connection/transaction/death-note-polling layer. State bytea decoding is unified via decodeBytea in the base instead of being duplicated per driver. Removes pg-bind from core-pg now that all queries use positional parameters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The third and largest adapter-base extraction (after digest #64 and journal #66) — the biggest single win, ~900 duplicated lines. Moves the ~40 pure-SQL core persistence methods into a shared
AbstractPostgresPersistenceAdapterin@telia-oss/xjog-core-persistence, written once with$Npositional SQL. core-pg/core-pglite keep only their driver layer.Design — generic over
ConnectionTypeCore's methods take a
connection?: ConnectionType(for transaction support), andwithTransactionhands that connection to callers. To avoid changing that callback type, the base stays generic:AbstractPostgresPersistenceAdapter<ConnectionType> extends PersistenceAdapter<ConnectionType>, with a single abstract normalizerEvery SQL method keeps its existing
(…, connection?)signature and callsthis.runQuery(connection, '<$N sql>', [params]). Only the SQL is unified; each driver's connection type andwithTransactionsemantics are untouched.Per driver
extends …<Pool | PoolClient>:runQuery(connection = this.pool, …)→rowCount ?? 0. Keepsconnect,disconnect,withTransaction(BEGIN/COMMIT/ROLLBACK on aPoolClient),onDeathNotepolling.pg-bindfully removed (dep +.d.ts).extends …<PGlite>:runQuery(connection = this.pool, …)→affectedRows ?? 0. Keepsconnect/disconnect/withTransaction(nativepool.transaction())/onDeathNote.rows.length(neverrowCount), since PGlite'saffectedRowsisundefinedfor SELECTs.charts.statebytea: reads decode via the shareddecodeBytea(util), writes useBuffer.from(JSON.stringify(state))— both in the base.Verification
The extracted base SQL is byte-identical to the SQL core-pglite already ran (pg's
:nameconverted to the same$N), so the 22-testPGlitePersistenceAdaptersuite passes unchanged and exercises the shared SQL that pg now runs too. Full-repoturbo run build test= 22/22 (core: 65 tests, same as baseline).lintclean.withTransactioncallers confirmed to only pass the connection back into persistence methods. One pre-existing quirk deliberately preserved:countPausedChartsreturns the raw driver value uncoerced. Changeset:minorfor the three core packages.Implements TODO item A4 — completes the pg/pglite dedup across all three families. Only A5 (real-Postgres smoke tests) remains in Track A.