Repository navigation
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 31 minutes. View limit details
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 |
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.
effect-orm has no relational read API. Each nested read becomes manual joins and grouping in app code.
Closes #79.
Part of #52.
Changes
Db.defineRelations(tables, (r) => ...)in/database:r.oneandr.manyrelations, declared over all tables in one callback, as Drizzle v2defineRelations. A relation names its target by key, so tables can point at each other. The types check the target, thefromandtocolumns, that both arestring | number | bigintkeys, and that a relation name is not a column name.Db.findMany(schema.table, { where, orderBy, limit, offset, with, crossTenant }): every column of the table plus each relation inwith, nested to any depth. Nested levels takewhere,orderByandwith. The row type follows thewithtree:manyis an array,oneis a row ornull.WHERE <to> IN (<keys from the level above>), then grouping in memory. A level with no keys sends nothing. Each level is an ordinary builder query, so each level decodes through its own row codec (a nestedtimestamptzis aDateTime.Utc) and has its owntenantScope.tenantColumnand the parent rows carry one tenant, the nested query gets<tenant column> = <that tenant>. Otherwise the level is cross-tenant, andrequireTenantScoperefuses it.crossTenant: truedeclares every level.design/relations.md: why one statement per level and not JSON aggregation, and the tenant rule.docs/relations.md, a typechecked example, and reference / README rows. Aminorchangeset.Left out
jsonb_agg, one statement). Each column type would need a JSON codec per dialect:int8loses precision as a JSON number,timestamptzandbyteachange format. It can come later as a second strategy behind the same API. Seedesign/relations.mdsection 3.columnsper level, alimitper parent on a nested level, composite keys, andfindFirst. Smallest slice first._countandsome/every/none(Relation counts and filters:_count,some,every,none#80).param.*in a nestedwhere:findManytakes no params.INlists (Postgres has a 65,535 bound-value limit). This belongs with Bound-parameter limits: chunkINlists and multi-row inserts #57.IN, so no dialect work is expected.Validation
bun run build: pass.bun run typecheck: pass (includessrc/database/relations.test-d.ts).bunx vitest run --testTimeout=60000 --hookTimeout=60000with live ClickHouse 26.8.2.7 (EFFECT_ORM_CLICKHOUSE_*set): 62 files, 1043 tests passed, 0 skipped.node scripts/check-doc-citations.mjs,node scripts/check-exports-documented.mjs,node scripts/check-doc-examples.mjs: pass.bun scripts/check-package.ts: pass.Need help on this PR? Tag
@codesmith-botwith what you need.