Skip to content

feat!: Add sql template and loader method#414

Merged
wschurman merged 1 commit intomainfrom
wschurman/02-01-feat_add_sql_template_and_loader_method
Feb 10, 2026
Merged

feat!: Add sql template and loader method#414
wschurman merged 1 commit intomainfrom
wschurman/02-01-feat_add_sql_template_and_loader_method

Conversation

@wschurman
Copy link
Member

@wschurman wschurman commented Feb 1, 2026

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:

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.

@wschurman wschurman force-pushed the wschurman/02-01-feat_add_sql_template_and_loader_method branch 2 times, most recently from cba5a4b to fa53992 Compare February 2, 2026 00:54
@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (aba0ce5) to head (f805905).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #414    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          106       108     +2     
  Lines        13941     14785   +844     
  Branches      1191      1302   +111     
==========================================
+ Hits         13941     14785   +844     
Flag Coverage Δ
integration 22.00% <91.24%> (+4.45%) ⬆️
unittest 96.50% <81.42%> (-0.92%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wschurman wschurman force-pushed the wschurman/02-01-feat_add_sql_template_and_loader_method branch 13 times, most recently from 4d4d971 to fe4ee5c Compare February 3, 2026 22:34
@wschurman wschurman force-pushed the wschurman/02-01-feat_add_codemod_for_upcoming_v0.55.0-v0.56.0 branch from ceba08f to da8f011 Compare February 4, 2026 03:31
@wschurman wschurman force-pushed the wschurman/02-01-feat_add_sql_template_and_loader_method branch from fe4ee5c to 1c65da3 Compare February 4, 2026 03:31
@wschurman wschurman requested a review from ide February 4, 2026 03:38
@wschurman wschurman marked this pull request as ready for review February 4, 2026 03:38
Copy link
Member

@ide ide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments

@wschurman wschurman force-pushed the wschurman/02-01-feat_add_sql_template_and_loader_method branch from 1c65da3 to eea3a17 Compare February 4, 2026 21:29
@wschurman wschurman force-pushed the wschurman/02-01-feat_add_codemod_for_upcoming_v0.55.0-v0.56.0 branch from da8f011 to 39f26e6 Compare February 4, 2026 21:29
@wschurman wschurman force-pushed the wschurman/02-01-feat_add_sql_template_and_loader_method branch 2 times, most recently from 098ab02 to cbd366a Compare February 4, 2026 21:58
@wschurman wschurman requested a review from ide February 4, 2026 23:39
@wschurman wschurman force-pushed the wschurman/02-01-feat_add_codemod_for_upcoming_v0.55.0-v0.56.0 branch from 39f26e6 to 831bf34 Compare February 9, 2026 23:28
@wschurman wschurman force-pushed the wschurman/02-01-feat_add_sql_template_and_loader_method branch from cbd366a to 674d0b3 Compare February 9, 2026 23:28
@wschurman wschurman force-pushed the wschurman/02-01-feat_add_codemod_for_upcoming_v0.55.0-v0.56.0 branch from 831bf34 to c50b36d Compare February 9, 2026 23:31
@wschurman wschurman force-pushed the wschurman/02-01-feat_add_sql_template_and_loader_method branch from 674d0b3 to b8ff387 Compare February 9, 2026 23:31
Copy link
Member Author

wschurman commented Feb 9, 2026

Merge activity

  • Feb 9, 11:36 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Feb 9, 11:57 PM UTC: Graphite rebased this pull request as part of a merge.
  • Feb 10, 12:00 AM UTC: @wschurman merged this pull request with Graphite.

wschurman added a commit that referenced this pull request Feb 9, 2026
# 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-knex` library. Therefore, the strategy is (in PR order):
1. Move existing knex/postgres-specific loader methods to a new loader, `knexLoader`. I'm also open to calling this a "Postgres Loader" since the `entity-database-adapter-knex` package 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.
1. Move knex-specific logic out of EntityDataManager, move it to its own EntityKnexDataManager.
1. Move these two now-separated pieces into the `entity-database-adapter-knex` package. 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.
1. Add a codemod for these three pieces.
1. Add the first new feature to entity loading, load by tagged template string, which creates a better/safer way to express raw queries for loading entities.

Future other things that could be added here (after thorough thought on authorization) are:
- Pagination
- Create, update, delete by tagged template string
- Batch creation
- Upsert (maybe)

# For Reviewers

The most critical things to assess are:
- "install" method in #410
- sql tagged template API usability in #414

# How

This is part 1. It refactors the loaders by moving `loadManyByFieldEqualityConjunctionAsync`, `loadFirstByFieldEqualityConjunctionAsync`, and `loadManyByRawWhereClauseAsync` to a separate loader.

The new pattern for these is:
```
await PostgresTestEntity.knexLoader(vc1).loadManyByRawWhereClauseAsync(...)
```

# Test Plan

This has full coverage in new tests.
@wschurman wschurman changed the base branch from wschurman/02-01-feat_add_codemod_for_upcoming_v0.55.0-v0.56.0 to graphite-base/414 February 9, 2026 23:53
@wschurman wschurman changed the base branch from graphite-base/414 to main February 9, 2026 23:56
@wschurman wschurman force-pushed the wschurman/02-01-feat_add_sql_template_and_loader_method branch from b8ff387 to f805905 Compare February 9, 2026 23:57
@wschurman wschurman merged commit 273d1df into main Feb 10, 2026
5 checks passed
@wschurman wschurman deleted the wschurman/02-01-feat_add_sql_template_and_loader_method branch February 10, 2026 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments