FORGE-85: jsonGet/jsonMerge and countAll/countWhere helpers #708

Merged
gmackie merged 1 commit from FORGE-85-json-helpers into main 2026-10-12 06:46:43 +00:00
Owner

Part 5 of FORGE-85 (D1 Phase 2, parent FORGE-69). Stacked on #706. No behaviour change.

  • packages/db/src/json.ts: jsonGet(col, key) (->>; keys limited to identifiers since they're inlined), jsonMerge(col, patch) (coalesce(col,'{}') || patch::jsonb), countAll(), countWhere(cond) (count(*) filter (where …) mapped to number; SQLite supports FILTER).
  • jsonGet: pipeline/kanbanger-notify.ts readiness lookup (3 filters).
  • jsonMerge: agent/ci-report/route.ts, agent/ci-progress/route.ts, fg/ci/report/route.ts (×2).
  • countAll/countWhere: routers/status.ts (6), routers/admin-stats.ts (9). Other count(*)::int sites (raw db.execute in registry etc.) are left; they'll move with their queries.
  • Semantics are documented in the module: jsonb || is a shallow merge (nested objects replaced, null stored as JSON null). SQLite's json_patch (RFC 7396) merges recursively and deletes null keys, so the SQLite port must use one json_set path per top-level key.

Verification

  • packages/api/src/__tests__/json-helpers.database.test.ts (6): NULL column, nested replacement, null preservation, ->> filter equivalence incl. missing key, key validation, counts equal to the old ::int casts and typed as numbers. Green on PGlite and Postgres 16.
  • Existing: ci-report/ci-progress/fg ci suites (107), kanbanger-notify (unit + DB), status telemetry.
  • tsc clean (db, api, web).

🤖 Generated with Claude Code

Part 5 of FORGE-85 (D1 Phase 2, parent FORGE-69). Stacked on #706. No behaviour change. - `packages/db/src/json.ts`: `jsonGet(col, key)` (`->>`; keys limited to identifiers since they're inlined), `jsonMerge(col, patch)` (`coalesce(col,'{}') || patch::jsonb`), `countAll()`, `countWhere(cond)` (`count(*) filter (where …)` mapped to number; SQLite supports FILTER). - jsonGet: pipeline/kanbanger-notify.ts readiness lookup (3 filters). - jsonMerge: agent/ci-report/route.ts, agent/ci-progress/route.ts, fg/ci/report/route.ts (×2). - countAll/countWhere: routers/status.ts (6), routers/admin-stats.ts (9). Other `count(*)::int` sites (raw `db.execute` in registry etc.) are left; they'll move with their queries. - Semantics are documented in the module: jsonb `||` is a shallow merge (nested objects replaced, null stored as JSON null). SQLite's `json_patch` (RFC 7396) merges recursively and deletes null keys, so the SQLite port must use one `json_set` path per top-level key. Verification - `packages/api/src/__tests__/json-helpers.database.test.ts` (6): NULL column, nested replacement, null preservation, `->>` filter equivalence incl. missing key, key validation, counts equal to the old `::int` casts and typed as numbers. Green on PGlite and Postgres 16. - Existing: ci-report/ci-progress/fg ci suites (107), kanbanger-notify (unit + DB), status telemetry. - tsc clean (db, api, web). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
FORGE-85: jsonGet/jsonMerge and countAll/countWhere helpers
Some checks failed
CI / gitleaks (pull_request) Successful in 8s
CI / unit-api (pull_request) Successful in 1m23s
CI / go (pull_request) Successful in 1m3s
CI / storybook (pull_request) Successful in 2m4s
CI / unit-web (pull_request) Successful in 1m58s
CI / database (pull_request) Successful in 2m8s
CI / ci (pull_request) Has been cancelled
CI / web-build (pull_request) Has been cancelled
CI / checks (pull_request) Has been cancelled
ee568decf3
packages/db/src/json.ts keeps the dialect-specific JSON and count SQL in
one place. jsonGet replaces the ->> filters in kanbanger-notify.ts;
jsonMerge replaces the jsonb || merges in agent/ci-report, agent/ci-progress
and fg/ci/report. jsonMerge is documented as a shallow merge (top-level
keys replaced wholesale, nulls stored), and why SQLite's json_patch
(RFC 7396: recursive merge, null deletes) is not a drop-in; the SQLite form
is one json_set path per top-level key.

countAll/countWhere replace count(*)::int and FILTER ... ::int in
routers/status.ts and routers/admin-stats.ts.

Tests: DB lane test pinning the shallow-merge and null semantics, ->>
equivalence, and count values against the old casts.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Author
Owner

Preview environment is live: https://pr-708-forgegraph.forgegraf.com

Deployed ee568dec with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.

Preview environment is live: https://pr-708-forgegraph.forgegraf.com Deployed `ee568dec` with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.
gmackie force-pushed FORGE-85-json-helpers from ee568decf3
Some checks failed
CI / gitleaks (pull_request) Successful in 8s
CI / unit-api (pull_request) Successful in 1m23s
CI / go (pull_request) Successful in 1m3s
CI / storybook (pull_request) Successful in 2m4s
CI / unit-web (pull_request) Successful in 1m58s
CI / database (pull_request) Successful in 2m8s
CI / ci (pull_request) Has been cancelled
CI / web-build (pull_request) Has been cancelled
CI / checks (pull_request) Has been cancelled
to 7bf1ad57f2
All checks were successful
CI / gitleaks (pull_request) Successful in 11s
CI / storybook (pull_request) Successful in 1m12s
CI / go (pull_request) Successful in 59s
CI / unit-api (pull_request) Successful in 2m3s
CI / checks (pull_request) Successful in 2m14s
CI / unit-web (pull_request) Successful in 1m58s
CI / database (pull_request) Successful in 3m15s
CI / web-build (pull_request) Successful in 4m45s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 36s
2026-10-12 04:48:24 +00:00
Compare
Author
Owner

Preview environment is live: https://pr-708-forgegraph.forgegraf.com

Deployed 7bf1ad57 with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.

Preview environment is live: https://pr-708-forgegraph.forgegraf.com Deployed `7bf1ad57` with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.
Author
Owner

Preview environment is live: https://pr-708-forgegraph.forgegraf.com

Deployed 7bf1ad57 with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.

Preview environment is live: https://pr-708-forgegraph.forgegraf.com Deployed `7bf1ad57` with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.
gmackie force-pushed FORGE-85-json-helpers from 7bf1ad57f2
All checks were successful
CI / gitleaks (pull_request) Successful in 11s
CI / storybook (pull_request) Successful in 1m12s
CI / go (pull_request) Successful in 59s
CI / unit-api (pull_request) Successful in 2m3s
CI / checks (pull_request) Successful in 2m14s
CI / unit-web (pull_request) Successful in 1m58s
CI / database (pull_request) Successful in 3m15s
CI / web-build (pull_request) Successful in 4m45s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 36s
to 568c468ea6
All checks were successful
CI / gitleaks (pull_request) Successful in 25s
CI / unit-web (pull_request) Successful in 4m21s
CI / unit-api (pull_request) Successful in 5m3s
CI / storybook (pull_request) Successful in 1m24s
CI / go (pull_request) Successful in 1m22s
CI / database (pull_request) Successful in 3m12s
CI / checks (pull_request) Successful in 3m31s
CI / web-build (pull_request) Successful in 3m36s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 50s
2026-10-12 05:26:14 +00:00
Compare
gmackie force-pushed FORGE-85-json-helpers from 568c468ea6
All checks were successful
CI / gitleaks (pull_request) Successful in 25s
CI / unit-web (pull_request) Successful in 4m21s
CI / unit-api (pull_request) Successful in 5m3s
CI / storybook (pull_request) Successful in 1m24s
CI / go (pull_request) Successful in 1m22s
CI / database (pull_request) Successful in 3m12s
CI / checks (pull_request) Successful in 3m31s
CI / web-build (pull_request) Successful in 3m36s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 50s
to 556591651e
All checks were successful
CI / gitleaks (pull_request) Successful in 23s
CI / unit-api (pull_request) Successful in 2m58s
CI / unit-web (pull_request) Successful in 3m56s
CI / storybook (pull_request) Successful in 1m54s
CI / go (pull_request) Successful in 1m5s
CI / database (pull_request) Successful in 2m32s
CI / web-build (pull_request) Successful in 3m46s
CI / checks (pull_request) Successful in 4m11s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 50s
2026-10-12 06:15:02 +00:00
Compare
gmackie changed target branch from FORGE-85-db-errors to main 2026-10-12 06:34:05 +00:00
Sign in to join this conversation.
No description provided.