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 42 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.
A team that uses effect-orm writes the same insert, update, findById and delete for each table, and must remember the tenant filter every time. Effect core has
SqlModel.makeRepositoryfor aModel.Class, but nothing builds it from an effect-orm table.Closes #75.
Part of #52.
Depends on #99; review only the commits after it. This branch builds on
tableSchemas(table)from #99. After #99 merges, I will rebase on main.Changes
makeRepository(table, { idColumn, tenantColumn })in/database. It returns an Effect that needsDatabase, likeSqlModel.makeRepositoryneedsSqlClient.insert,insertVoid,update,updateVoid,findById,delete.findByIdandupdatereturn anOption(Option.fromNullishOron the first row).insertreturns the stored row with its defaults.tableSchemas(table):inserttakes theinsertrow, a patch takes theupdaterow. A patch cannot set the id.TenantRepository. Every method takes the tenant first. Inserts write the tenant column from that argument, and the row type has no tenant column. Reads and writes filter on the tenant column and the id. A patch cannot set the tenant column. A tenant column put into a row or patch at runtime (through a cast) is removed. Each statement compiles as"single-tenant", so aDatabasewithrequireTenantScoperuns it.Tabletype does not carry its tenant column (it is widened tostringon purpose), somakeRepositorycheckstenantColumnagainsttable.tenantColumnwhen it is built. A mismatch in either direction is aQueryBuilderDefect.insertVoid,updateVoid,findByIdanddeletework.updateVoidis a mutation withmutations_sync = 2, anddeletea lightweight delete withlightweight_deletes_sync = 2, so afindByIdafter them reads the write.insertandupdateneedRETURNING, which ClickHouse does not have, so they die with the existingQueryBuilderDefectand write nothing. The choice uses the dialect'sclauses(writeSettings,alterTableUpdate), not its name.src/database/repository.test.ts, run withrequireTenantScope: true), type tests (src/database/repository.test-d.ts), and a live ClickHouse suite (tests/repository.clickhouse.test.ts).docs/database.md, a row indocs/reference.md, the docs index, and aminorchangeset.Left out
deletedAt). It is optional in the issue. It can be one more option later.insertwould needLAST_INSERT_ID()as inSqlModel.Database#76 / PR feat(database): layerTest, a Database with no server for unit tests #93). The repository is a plain value overDatabase, so that Layer can wrap it later.runOne/runOptionfrom feat(database): runOne, runOption and runNonEmpty cardinality helpers #92. This PR does not depend on it;findByIdusesOption.fromNullishOron the first row.SqlModel'sspanPrefix). Each statement already has its own span fromDatabase.makeRepository. It would needTableto carry the tenant column as a literal type, which is a larger change. The check runs when the repository is built.FINALon ClickHousefindById. On aReplacingMergeTreeit can read an older version. The docs say so.Validation
Run on
b4f5c51against a live ClickHouse 26.8.2.7 (the CI matrix version), withEFFECT_ORM_CLICKHOUSE_URLset, so no suite is skipped:bun run build: pass.bun run typecheck: pass.vitest run --testTimeout=60000 --hookTimeout=60000: pass. Test files: 63 passed (63). Tests: 1051 passed (1051).bun scripts/check-package.ts(tarball, types, CommonJS consumer): pass.Need help on this PR? Tag
@codesmith-botwith what you need.