Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
78b4db1 to
8efee7b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #407 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 91 96 +5
Lines 12694 13144 +450
Branches 1101 664 -437
==========================================
+ Hits 12694 13144 +450
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
5148002 to
fd886c7
Compare
fd886c7 to
a0423c5
Compare
ide
left a comment
There was a problem hiding this comment.
Reorganizing the code so the Knex-related parts are closer together seems fine to me.
I don't think the knexLoader is necessary to aid LLMs, which are just as happy to read docblocks. Or we could add "Knex" to the names of the Knex methods.
The eventual refactoring in #410 seems partly off to me. Specifically, EntityPrivacyUtils moves to the knex package but to me it seems like a general concern, regardless of whether Knex is used. Maybe that is not the case.
I worry this refactoring is in a partway state where the lines of separation aren't well drawn and it would be better to export everything from the main entitty package and have the knex package be an internal hard dependency.
|
The current abstraction is at the adapter layer. What has happened though is that SQL-specific (knex adapter-specific) logic has leaked into the main entity package ( What we're seeing is that the quantity of adapter-specific logic and types that are leaking into the main package is increasing. We added The way I'm thinking about this is by hypothetically having N database adapter flavors already in existence. (We technically already do because of the unit test adapters, but not a production adapter, though there have been talks about having them for other databases.) To add So, there's a couple options:
EntityPrivacyUtils is an interesting case and you're right to point it out. It uses Re: LLMs - it's more about making things easier to lint and instruct. For example, I'd like to have a PR comment posting requesting |
|
That all makes sense. For EntityPrivacyUtils: I think the notion of "one", as opposed to "first", makes sense for all databases. It's not a SQL/RDBMS concept. Some databases can implement "one" using "first". We would replace |
a0423c5 to
00bb4a7
Compare
Merge activity
|
# Why Part 2 of #407. # How Refactor methods into a separate class for future move out of main package. # Test Plan Full test coverage.
) # Why Part 3 of #407. # How This is the main PR of the stack. It creates a mechanism for "installing" the extension methods on required objects, and then installs them and tests them. The goal is to make it better self-contained about what is core in the library and guaranteed to be efficient (dataloader'd and cached) and what is not (raw SQL and SQLFragment loads in a future PR). This is becoming more critical in a time of agentic coding where having a discrete set of loaders that can be linted separately and instruct agents to run `EXPLAIN ANALYZE` in raw cases. # Test Plan Full test coverage.
# Why This is the first new feature afforded by the changes in #407. It adds a feature that is fairly common amongst typescript ORMs: sql via tagged templates for safe value interpolation into SQL statements. # How Quite a lot of ORMs have this: - https://github.com/drizzle-team/drizzle-orm - https://github.com/mikro-orm/mikro-orm - https://github.com/blakeembrey/sql-template-tag - https://github.com/andywer/squid - https://github.com/Seb-C/kiss-orm This adds support for it to entity knex. See tests for examples, especially `PostgresEntityIntegration-test.ts`. The idea is that this will replace `loadManyByRawWhereClauseAsync` over the course of a few versions. # Test Plan Full test coverage.

Why
This is a long stack, but the goal is to make a place to put postgres-specific loading logic to avoid polluting the core dataloader-based library with logic specific to knex/postgres. And potentially even postgres-specific mutation logic but that's way down the road.
The best place for this stuff is in the
entity-database-adapter-knexlibrary. Therefore, the strategy is (in PR order):knexLoader. I'm also open to calling this a "Postgres Loader" since theentity-database-adapter-knexpackage already uses postgres-specific queries (and more are added here since this stack eventually produces raw queries) within knex even though technically knex is database agnostic.entity-database-adapter-knexpackage. This requires creating a "plugin" system for database adapters, where when they are included their methods are added to the prototype so that seamless loading continues to work.Future other things that could be added here (after thorough thought on authorization) are:
For Reviewers
The most critical things to assess are:
How
This is part 1. It refactors the loaders by moving
loadManyByFieldEqualityConjunctionAsync,loadFirstByFieldEqualityConjunctionAsync, andloadManyByRawWhereClauseAsyncto a separate loader.The new pattern for these is:
Test Plan
This has full coverage in new tests.