Skip to content

feat: update the SQLExpression and SQLFragmentHelpers APIs#516

Open
wschurman wants to merge 1 commit intomainfrom
wschurman/03-09-chore_update_docs_for_sqlexpression
Open

feat: update the SQLExpression and SQLFragmentHelpers APIs#516
wschurman wants to merge 1 commit intomainfrom
wschurman/03-09-chore_update_docs_for_sqlexpression

Conversation

@wschurman
Copy link
Member

@wschurman wschurman commented Mar 9, 2026

Why

The expression API added in #506 was somewhat poisonous. When doing something like jsonPath('fieldName', 'wat').eq(10), the type information was lost due to typescript not carrying it through chains. So I could do something like:

BlahEntity.knexLoader()..loadManyBySQL(sql`${entityField('hadsACat')} = ${true}`)

and it would correctly tell me that the field name is invalid (type info carries into single arg).

But the following wouldn't:

BlahEntity.knexLoader().loadBySQL(expression('hadsACat').eq(true))

How

It's better to just get rid of expression though keep the fluent API on SQLFragmentHelper methods that can carry the type information through the chain.

This PR does a few things:

  • adds the required code to carry that type information through
  • updates SQLFragmentHelper methods to take either an expression/fragment or entity field name for better usability.
  • renames SQLExpression to SQLChainableFragment to better describe what it does
  • renames SQLFragmentHelper to SQLExpression to better describe the class of things it contains.

Test Plan

Run new tests.

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (090c046) to head (cfec837).

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #516    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          110       110            
  Lines        16718     17136   +418     
  Branches      1519      1518     -1     
==========================================
+ Hits         16718     17136   +418     
Flag Coverage Δ
integration 27.05% <74.21%> (+1.48%) ⬆️
unittest 95.07% <99.43%> (+0.12%) ⬆️

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/03-09-chore_update_docs_for_sqlexpression branch from 9536556 to 280809a Compare March 10, 2026 23:02
@wschurman wschurman changed the title chore: update docs for SQLExpression feat: update the SQLExpression and SQLFragmentHelpers APIs Mar 10, 2026
@wschurman wschurman force-pushed the wschurman/03-09-chore_update_docs_for_sqlexpression branch 2 times, most recently from 67754b8 to 2b4a3d1 Compare March 11, 2026 00:21
@wschurman wschurman requested a review from quinlanj March 11, 2026 00:29
@wschurman wschurman marked this pull request as ready for review March 11, 2026 00:29
@wschurman wschurman force-pushed the wschurman/03-09-chore_update_docs_for_sqlexpression branch 2 times, most recently from 58fcbf8 to 196c821 Compare March 11, 2026 15:55
@wschurman wschurman force-pushed the wschurman/03-09-chore_update_docs_for_sqlexpression branch from 196c821 to cfec837 Compare March 11, 2026 15:58
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