Skip to content

chore(drizzle): alias _query to query and enforce via lint#3118

Closed
RSO wants to merge 6 commits intomainfrom
RSO/silent-sphere
Closed

chore(drizzle): alias _query to query and enforce via lint#3118
RSO wants to merge 6 commits intomainfrom
RSO/silent-sphere

Conversation

@RSO
Copy link
Copy Markdown
Contributor

@RSO RSO commented May 7, 2026

Summary

Prep for drizzle v1, which renames the RQB namespace from query to _query. This change adds a runtime alias so both names work today, rewrites every .query drizzle receiver to ._query, and enforces the new name going forward.

  • New @kilocode/drizzle-shims package patches PgDatabase.prototype and BaseSQLiteDatabase.prototype with a _query getter that returns this.query. Transaction subclasses (PgTransaction, SQLiteTransaction) inherit the alias automatically, so tx._query works everywhere too. Includes module augmentations so TypeScript sees _query on every drizzle db flavour.
  • Side-effect imports (import '@kilocode/drizzle-shims/query-alias';) at every drizzle(...) construction site — packages/db/src/client.ts plus 12 DO service files. The new workspace dep was added to each affected service.
  • oxlint-plugin-drizzle.js gains prefer-underscore-query (AST-only, autofixable, name-gated on ["db", "ctx.db", "this.db", "tx", "trx"] — same posture as the existing two drizzle rules). Enabled as "error" in .oxlintrc.json.
  • scripts/drizzle-query-rename.ts — ts-morph codemod / CI verifier. Because oxlint plugins can't see types, this script is the authoritative check: it walks every workspace tsconfig plus dev/ and scripts/ orphan files and identifies .query property accesses whose query property is declared inside drizzle-orm. Runs as pnpm drizzle:query-rename (--fix) or pnpm drizzle:query-check; the latter is wired into pnpm validate.
  • 372 call sites across 76 files rewritten from .query to ._query.

When drizzle v1 lands, delete packages/drizzle-shims/, the 13 side-effect imports, the oxlint rule, and the codemod script. The codebase already reads from _query.

Verification

Example of a run that finds calls to .query:

silent-sphere on  RSO/silent-sphere [$⇕] via  v24.14.1 on ☁️  (eu-central-1) took 2s
❯ pnpm drizzle:query-check

> kilocode-monorepo@0.1.0 drizzle:query-check /Users/remon/.superset/worktrees/cloud/RSO/silent-sphere
> tsx scripts/drizzle-query-rename.ts --check

[drizzle-query-rename] scanning 44 tsconfigs
[drizzle-query-rename] scanning 30 orphan files (dev/, scripts/)
apps/web/src/lib/impact-referral.test.ts: 3 hit(s)
  414:39
  420:45
  480:36
apps/web/src/lib/impact-referral.ts: 5 hit(s)
  238:21
  402:35
  516:28
  523:32
  607:36
apps/web/src/lib/kiloclaw-referrals.ts: 6 hit(s)
  1110:31
  1353:33
  1400:29
  1460:33
  1675:41
  2133:17
apps/web/src/lib/organizations/organization-billing.test.ts: 12 hit(s)
  54:13
  796:40
  872:33
  903:33
  944:33
  951:35
  959:32
  1012:33
  1040:33
  1048:35
  1072:33
  1080:35
[drizzle-query-rename] total: 26 hit(s) in 4 file(s)
[drizzle-query-rename] failing: use `pnpm drizzle:query-rename` or `oxlint --fix` to migrate.

Reviewer Notes

  • The alias is intentionally temporary. It's documented as such at the top of packages/drizzle-shims/src/query-alias.ts with clear removal instructions for the drizzle v1 migration.
  • The oxlint rule is name-based because oxlint JS plugins are AST-only. The ts-morph CI check is the source of truth — it catches any drizzle db in the repo regardless of what it's named (handy for destructured dbs, txn/trx renames, helpers returning a drizzle db, etc.).
  • Rollup emits a cosmetic warning when building @kilocode/trpc's .d.ts about @kilocode/drizzle-shims/query-alias being an external dep. It's benign (the import is type-only from consumers' perspective and resolves via the workspace), but worth flagging.
  • Risk is concentrated at two points: (1) the prototype mutation in query-alias.ts — only additive, no setter, idempotent, non-enumerable; and (2) the codemod correctness — mitigated by the type-aware check, the full test suite passing, and targeted typechecks. Worth spot-checking a handful of rewrites (e.g. apps/web/src/lib/kilo-pass/usage-triggered-bonus.ts) to confirm semantics are preserved.

Comment thread scripts/drizzle-query-rename.ts Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 7, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 file)
  • apps/web/src/lib/integrations/platforms/github/batch-review-decisions.test.ts

Reviewed by gpt-5.5-2026-04-23 · 761,150 tokens

RSO added 4 commits May 8, 2026 08:07
Prep for drizzle v1, which renames the RQB namespace from `query` to
`_query`. Adds a runtime alias so both names work, rewrites every
`.query` drizzle receiver to `._query`, and enforces the new name with
an oxlint rule plus a type-aware CI check.

- New `@kilocode/drizzle-shims` package patches PgDatabase and
  BaseSQLiteDatabase prototypes with a `_query` getter; transaction
  subclasses (`tx._query`) are covered automatically.
- Side-effect imports added at every `drizzle(...)` construction site
  (packages/db client plus 12 DO service files).
- `oxlint-plugin-drizzle.js` gains `prefer-underscore-query` (autofix,
  name-gated: db / ctx.db / this.db / tx / trx).
- `scripts/drizzle-query-rename.ts` is a ts-morph codemod/verifier that
  walks every workspace tsconfig plus dev/ and scripts/ orphans and
  checks the drizzle `query` property by declaration location. Exposed
  as `pnpm drizzle:query-rename` and `pnpm drizzle:query-check`; the
  check runs as part of `pnpm validate`.
- 372 call sites across 76 files rewritten.
Adds a 'Drizzle _query enforcement' step to the lint job that runs
`pnpm drizzle:query-check`. The oxlint rule already blocks the common
cases (db / ctx.db / this.db / tx / trx); the ts-morph verifier catches
the type-aware long tail so a renamed drizzle db can't sneak past. Both
exit non-zero on a fresh `.query` — verified by injecting a canary.
@RSO RSO force-pushed the RSO/silent-sphere branch from c229c87 to e5d63e1 Compare May 8, 2026 06:10
RSO added 2 commits May 8, 2026 08:32
apps/web tsconfig uses moduleResolution: node, which doesn't honor the
shim package's exports map (.ts source files). Without resolution, the
_query type augmentation never loads and next build fails type checking.
Add a path mapping mirroring the existing @kilocode/db/* pattern.
…gle tick

The single macrotask tick was fast enough locally but not on CI's
slower Postgres, where the claimPendingReviewRows UPDATE round-trip
hadn't returned before the assertion fired.
@RSO
Copy link
Copy Markdown
Contributor Author

RSO commented May 8, 2026

@RSO RSO closed this May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants