chore(orm): use "json_each" instead of "jsonb_each" for better compatibility#484
chore(orm): use "json_each" instead of "jsonb_each" for better compatibility#484
Conversation
WalkthroughChanges include switching JSON functions from Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Claude finished @ymc9's task —— View job Pull Request ReviewReview Checklist
Code Review SummaryThis PR makes two main types of changes:
Detailed Feedback✅ Code Quality & Best PracticesExcellent: The core change is well-targeted and follows SQLite best practices:
Good: Test cleanup improvements:
✅ Compatibility & PerformanceCritical Fix: This change resolves a serious compatibility issue:
✅ Security Considerations
✅ Test CoverageComprehensive: Changes span 17 test files across:
Appropriate scope: Only test setup changes, no test logic modifications needed since the API remains identical.
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/orm/src/client/crud/dialects/sqlite.ts (1)
371-393: Prefer buildingarray_containswith Kyselyexists(avoid raw SQL + unaliasedvalue).This keeps the JSON array paths consistent with
buildJsonArrayExistsPredicate, and avoids relying on the barevaluecolumn name fromjson_each(...).- return sql<any>`EXISTS (SELECT 1 FROM json_each(${lhs}) WHERE value = ${value})`; + return this.eb.exists( + this.eb + .selectFrom(this.eb.fn('json_each', [lhs]).as('$items')) + .select(this.eb.lit(1).as('$t')) + .whereRef('$items.value', '=', this.eb.val(value)), + );
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (19)
packages/orm/src/client/crud/dialects/sqlite.ts(2 hunks)tests/e2e/orm/client-api/aggregate.test.ts(1 hunks)tests/e2e/orm/client-api/count.test.ts(1 hunks)tests/e2e/orm/client-api/create-many-and-return.test.ts(1 hunks)tests/e2e/orm/client-api/create-many.test.ts(1 hunks)tests/e2e/orm/client-api/create.test.ts(1 hunks)tests/e2e/orm/client-api/delete-many.test.ts(1 hunks)tests/e2e/orm/client-api/delete.test.ts(1 hunks)tests/e2e/orm/client-api/find.test.ts(1 hunks)tests/e2e/orm/client-api/group-by.test.ts(1 hunks)tests/e2e/orm/client-api/raw-query.test.ts(1 hunks)tests/e2e/orm/client-api/transaction.test.ts(1 hunks)tests/e2e/orm/client-api/undefined-values.test.ts(1 hunks)tests/e2e/orm/client-api/update-many.test.ts(1 hunks)tests/e2e/orm/client-api/update.test.ts(1 hunks)tests/e2e/orm/plugin-infra/on-kysely-query.test.ts(1 hunks)tests/e2e/orm/plugin-infra/on-query-hooks.test.ts(1 hunks)tests/e2e/orm/policy/basic-schema-read.test.ts(1 hunks)tests/e2e/orm/policy/policy-functions.test.ts(0 hunks)
💤 Files with no reviewable changes (1)
- tests/e2e/orm/policy/policy-functions.test.ts
🧰 Additional context used
📓 Path-based instructions (1)
tests/e2e/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
E2E tests should validate real-world schema compatibility with established projects
Files:
tests/e2e/orm/client-api/undefined-values.test.tstests/e2e/orm/client-api/update-many.test.tstests/e2e/orm/client-api/create.test.tstests/e2e/orm/policy/basic-schema-read.test.tstests/e2e/orm/client-api/transaction.test.tstests/e2e/orm/client-api/raw-query.test.tstests/e2e/orm/client-api/delete.test.tstests/e2e/orm/plugin-infra/on-query-hooks.test.tstests/e2e/orm/client-api/count.test.tstests/e2e/orm/plugin-infra/on-kysely-query.test.tstests/e2e/orm/client-api/delete-many.test.tstests/e2e/orm/client-api/group-by.test.tstests/e2e/orm/client-api/find.test.tstests/e2e/orm/client-api/aggregate.test.tstests/e2e/orm/client-api/create-many.test.tstests/e2e/orm/client-api/create-many-and-return.test.tstests/e2e/orm/client-api/update.test.ts
🧠 Learnings (6)
📚 Learning: 2025-10-21T16:04:56.292Z
Learnt from: ymc9
Repo: zenstackhq/zenstack-v3 PR: 319
File: packages/runtime/src/client/crud/dialects/base-dialect.ts:745-747
Timestamp: 2025-10-21T16:04:56.292Z
Learning: In packages/runtime/src/client/crud/dialects/base-dialect.ts, it's intentional that buildCursorFilter applies default ordering (via makeDefaultOrderBy fallback) while buildOrderBy does not. This ensures cursor-based pagination always has stable ordering for correctness, while regular queries remain unordered unless explicitly specified. This design is to be consistent with Prisma's pagination requirements.
Applied to files:
packages/orm/src/client/crud/dialects/sqlite.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.{ts,tsx} : Use Kysely as the query builder interface for low-level database queries, avoiding raw SQL when possible
Applied to files:
packages/orm/src/client/crud/dialects/sqlite.tstests/e2e/orm/client-api/raw-query.test.tstests/e2e/orm/plugin-infra/on-query-hooks.test.tstests/e2e/orm/plugin-infra/on-kysely-query.test.tstests/e2e/orm/client-api/find.test.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.test.{ts,tsx} : ORM package tests should include comprehensive client API tests and policy tests
Applied to files:
tests/e2e/orm/client-api/undefined-values.test.tstests/e2e/orm/client-api/update-many.test.tstests/e2e/orm/client-api/create.test.tstests/e2e/orm/policy/basic-schema-read.test.tstests/e2e/orm/client-api/transaction.test.tstests/e2e/orm/client-api/raw-query.test.tstests/e2e/orm/client-api/delete.test.tstests/e2e/orm/plugin-infra/on-query-hooks.test.tstests/e2e/orm/client-api/count.test.tstests/e2e/orm/plugin-infra/on-kysely-query.test.tstests/e2e/orm/client-api/delete-many.test.tstests/e2e/orm/client-api/group-by.test.tstests/e2e/orm/client-api/find.test.tstests/e2e/orm/client-api/aggregate.test.tstests/e2e/orm/client-api/create-many.test.tstests/e2e/orm/client-api/create-many-and-return.test.tstests/e2e/orm/client-api/update.test.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/e2e/**/*.{ts,tsx} : E2E tests should validate real-world schema compatibility with established projects
Applied to files:
tests/e2e/orm/client-api/undefined-values.test.tstests/e2e/orm/client-api/update-many.test.tstests/e2e/orm/client-api/create.test.tstests/e2e/orm/policy/basic-schema-read.test.tstests/e2e/orm/client-api/transaction.test.tstests/e2e/orm/client-api/raw-query.test.tstests/e2e/orm/client-api/delete.test.tstests/e2e/orm/plugin-infra/on-query-hooks.test.tstests/e2e/orm/client-api/count.test.tstests/e2e/orm/plugin-infra/on-kysely-query.test.tstests/e2e/orm/client-api/delete-many.test.tstests/e2e/orm/client-api/group-by.test.tstests/e2e/orm/client-api/find.test.tstests/e2e/orm/client-api/aggregate.test.tstests/e2e/orm/client-api/create-many.test.tstests/e2e/orm/client-api/create-many-and-return.test.tstests/e2e/orm/client-api/update.test.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to tests/**/type*.{ts,tsx} : Ensure TypeScript inference and type coverage are validated through type coverage tests
Applied to files:
tests/e2e/orm/client-api/update-many.test.tstests/e2e/orm/client-api/create.test.tstests/e2e/orm/client-api/delete.test.tstests/e2e/orm/client-api/find.test.ts
📚 Learning: 2025-11-26T01:55:04.540Z
Learnt from: CR
Repo: zenstackhq/zenstack-v3 PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-26T01:55:04.540Z
Learning: Applies to packages/zenstackhq/orm/**/*.{ts,tsx} : Implement plugin hooks at ORM, Kysely, and entity mutation levels for query interception and customization
Applied to files:
tests/e2e/orm/client-api/update-many.test.tstests/e2e/orm/client-api/create.test.tstests/e2e/orm/policy/basic-schema-read.test.tstests/e2e/orm/client-api/transaction.test.tstests/e2e/orm/client-api/raw-query.test.tstests/e2e/orm/client-api/delete.test.tstests/e2e/orm/plugin-infra/on-query-hooks.test.tstests/e2e/orm/plugin-infra/on-kysely-query.test.tstests/e2e/orm/client-api/find.test.tstests/e2e/orm/client-api/create-many-and-return.test.ts
🧬 Code graph analysis (4)
tests/e2e/orm/client-api/undefined-values.test.ts (1)
packages/testtools/src/client.ts (1)
createTestClient(101-248)
tests/e2e/orm/client-api/count.test.ts (1)
packages/testtools/src/client.ts (1)
createTestClient(101-248)
tests/e2e/orm/plugin-infra/on-kysely-query.test.ts (1)
packages/testtools/src/client.ts (1)
createTestClient(101-248)
tests/e2e/orm/client-api/update.test.ts (1)
packages/testtools/src/client.ts (1)
createTestClient(101-248)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Agent
- GitHub Check: CodeQL analysis (javascript-typescript)
- GitHub Check: build-test (20.x, postgresql)
- GitHub Check: build-test (20.x, sqlite)
🔇 Additional comments (11)
packages/orm/src/client/crud/dialects/sqlite.ts (1)
395-405:json_eachswitch looks correct; please verify runtime support matrix (SQLite JSON1 / versions).If any supported environment lacks JSON1 (or has it disabled),
json_each(...)will fail at runtime—worth confirming against your documented minimum SQLite version / build options.tests/e2e/orm/policy/basic-schema-read.test.ts (1)
11-11: LGTM! Clean refactor removing redundant type cast.The
as anycast was unnecessary sincecreateTestClientalready returnsPromise<any>. This change improves readability while maintaining the same runtime behavior.tests/e2e/orm/client-api/create-many.test.ts (1)
10-10: LGTM! Clean refactor removing redundant type cast.Removing the
as anycast improves code clarity without affecting behavior.tests/e2e/orm/plugin-infra/on-query-hooks.test.ts (1)
10-10: LGTM! Clean refactor removing redundant type cast.Consistent with the broader refactoring pattern across the test suite.
tests/e2e/orm/plugin-infra/on-kysely-query.test.ts (1)
11-11: LGTM! Clean refactor removing redundant type cast.tests/e2e/orm/client-api/create-many-and-return.test.ts (1)
10-10: LGTM! Clean refactor removing redundant type cast.tests/e2e/orm/client-api/undefined-values.test.ts (1)
11-11: LGTM! Clean refactor removing redundant type cast.tests/e2e/orm/client-api/aggregate.test.ts (1)
11-11: LGTM! Clean refactor removing redundant type cast.tests/e2e/orm/client-api/count.test.ts (1)
10-10: LGTM! Clean refactor removing redundant type cast.This completes the consistent refactoring pattern across the entire test suite.
tests/e2e/orm/client-api/group-by.test.ts (1)
10-11: LGTM: Type-safety improvement across test suite.The removal of the explicit
as anycast when initializing the test client is a good refinement. SincecreateTestClientalready returnsPromise<any>, the cast was redundant. Relying on TypeScript's type inference maintains the same runtime behavior while improving code clarity.This pattern is consistently applied across multiple test files (group-by, delete, find, update, update-many, transaction, delete-many, create), which demonstrates thorough cleanup.
tests/e2e/orm/client-api/raw-query.test.ts (1)
9-11: Good simplification; no behavior change.Since
createTestClient(schema)already returnsPromise<any>, dropping the explicitas anykeeps the same effective typing while reducing noise.
There was a problem hiding this comment.
Pull request overview
This PR improves SQLite compatibility by replacing jsonb_each with the standard json_each function, along with minor test code cleanups.
- Updates SQLite dialect to use
json_eachinstead ofjsonb_eachfor better compatibility with older SQLite versions - Removes unnecessary
as anytype assertions from test files - Removes debug flag from policy functions test
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/orm/src/client/crud/dialects/sqlite.ts | Changed jsonb_each to json_each in two locations for array operations to improve compatibility with older SQLite versions |
| tests/e2e/orm/policy/policy-functions.test.ts | Removed debug flag from test configuration |
| tests/e2e/orm/policy/basic-schema-read.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/plugin-infra/on-query-hooks.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/plugin-infra/on-kysely-query.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/update.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/update-many.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/undefined-values.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/transaction.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/raw-query.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/group-by.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/find.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/delete.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/delete-many.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/create.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/create-many.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/create-many-and-return.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/count.test.ts | Removed unnecessary as any type assertion from client initialization |
| tests/e2e/orm/client-api/aggregate.test.ts | Removed unnecessary as any type assertion from client initialization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.