Skip to content

WIP functional variants of the select, where and having query builder methods #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2025

Conversation

samwillis
Copy link
Collaborator

stacked on #185

In the old query builder you could call the same methods with a callback for the functional behaviour, but with the new query builder its always a callback with makes the api very hard to function as both an expression builder or functional callback. Because of that I think it's best to split these variates out as distinct functions.

For this first pass I have namespaces these under .fn on the query builder, but we could have then on the main object with a prefix/suffix.

const liveCollection = createLiveQueryCollection({
  startSync: true,
  query: (q) =>
    q
      .from({ user: usersCollection })
      .fn.select((row) => ({
        displayName: `${row.user.name} (${row.user.id})`,
        salaryTier: row.user.salary > 60000 ? `senior` : `junior`,
        emailDomain: row.user.email.split(`@`)[1],
      })),
})

I like the namespace as it nicely groups them as well as moving deeper in the editor prompts, somewhat demoting them to a second tier.

Looking for feedback on this before finishing touches (if were happy its 95% done)

@samwillis samwillis requested a review from KyleAMathews June 27, 2025 22:10
Copy link

changeset-bot bot commented Jun 27, 2025

⚠️ No Changeset found

Latest commit: 0bbd79a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

pkg-pr-new bot commented Jun 27, 2025

@tanstack/db-example-react-todo

npm i https://pkg.pr.new/@tanstack/db@215
npm i https://pkg.pr.new/@tanstack/db-collections@215
npm i https://pkg.pr.new/@tanstack/react-db@215
npm i https://pkg.pr.new/@tanstack/vue-db@215

commit: 0bbd79a

Copy link
Contributor

Size Change: +466 B (+1.68%)

Total Size: 28.2 kB

Filename Size Change
./packages/db/dist/esm/query/builder/index.js 1.7 kB +303 B (+21.67%) 🚨
./packages/db/dist/esm/query/compiler/group-by.js 2.08 kB +72 B (+3.59%)
./packages/db/dist/esm/query/compiler/index.js 1.4 kB +91 B (+6.94%) 🔍
ℹ️ View Unchanged
Filename Size
./packages/db/dist/esm/collection.js 7.69 kB
./packages/db/dist/esm/deferred.js 230 B
./packages/db/dist/esm/errors.js 150 B
./packages/db/dist/esm/index.js 572 B
./packages/db/dist/esm/optimistic-action.js 294 B
./packages/db/dist/esm/proxy.js 3.75 kB
./packages/db/dist/esm/query/builder/functions.js 529 B
./packages/db/dist/esm/query/builder/ref-proxy.js 851 B
./packages/db/dist/esm/query/compiler/evaluators.js 1.34 kB
./packages/db/dist/esm/query/compiler/joins.js 1.16 kB
./packages/db/dist/esm/query/compiler/order-by.js 933 B
./packages/db/dist/esm/query/compiler/select.js 657 B
./packages/db/dist/esm/query/ir.js 310 B
./packages/db/dist/esm/query/live-query-collection.js 1.98 kB
./packages/db/dist/esm/SortedMap.js 1.24 kB
./packages/db/dist/esm/transactions.js 1.33 kB

compressed-size-action::db-package-size

Copy link
Contributor

Size Change: 0 B

Total Size: 665 B

ℹ️ View Unchanged
Filename Size
./packages/react-db/dist/esm/index.js 152 B
./packages/react-db/dist/esm/useLiveQuery.js 513 B

compressed-size-action::react-db-package-size

Copy link
Collaborator

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

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

Makes sense to me as that's easy to understand and discoverable

@samwillis samwillis marked this pull request as ready for review June 28, 2025 07:04
@samwillis samwillis merged commit 8e1368d into query2 Jun 28, 2025
4 checks passed
@samwillis samwillis deleted the query2-fn branch June 28, 2025 07:05
@samwillis
Copy link
Collaborator Author

Merged into the main query2 branch

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