Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #565 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 110 110
Lines 17424 17694 +270
Branches 1505 1519 +14
==========================================
+ Hits 17424 17694 +270
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:
|
ea3c0cd to
4a4593d
Compare
521941d to
52b9604
Compare
|
For upsert, there is now MERGE in Postgres. Awhile ago Sonnet 4.6 claimed it was not as efficient as ON CONFLICT but I think it would be best to profile both in a production scenario and see if we can tell a difference in the Grafana query stats. |
| const query = this.applyFieldEqualityConjunctionWhereClause( | ||
| queryInterface.count('* as count').from(tableName), | ||
| tableFieldSingleValueEqualityOperands, | ||
| tableFieldMultiValueEqualityOperands, | ||
| ); |
There was a problem hiding this comment.
This is subtle but worth adding a test for IMO: if we have a WHERE clause that tries to match on count = ?, this count refers to a column named count in the table - not the `count(*). (If no such column exists, PG fails)
There was a problem hiding this comment.
Nice catch! Renamed the count to __entity_count__ and marked it as reserved.
packages/entity-database-adapter-knex/src/PostgresEntityDatabaseAdapter.ts
Outdated
Show resolved
Hide resolved
|
Another concern I have is performance, specifically big scans taking a long time. Docblocks that emphasize this seem important. |
52b9604 to
79fb324
Compare
|
Added a docblock to emphasize that indexes are just as critical for these count methods as they are for their non-count counterparts. |
79fb324 to
eab360e
Compare
eab360e to
7e414b6
Compare

Why
Looking at more ways the Expo server application needs escape hatches from entity, particularly in postgres/knex, it's:
In other PRs I'm looking into batch stuff, but it's quite complex. In the meantime, some easy wins are count and upsert.
How
Adds count equivalents for knex loads. Note that these purposefully don't do authorization since the point of these is to not need to load the full row set, and authorization is row-based.
Test Plan
Run tests.