© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
9 replies
terryball

Chaining/combining $dynamic query functions

Hi everyone -

I'm trying to take advantage of the new dynamic query building feature to simplify the way I query my db for displaying data in a table. I've already implemented a nice helper function to add ORDER BY to a query, e.g:

const result = await withOrderBy(qb, {
  orderBy: 'name',
  order: 'desc'
})
const result = await withOrderBy(qb, {
  orderBy: 'name',
  order: 'desc'
})


And now I'd like to do the same for pagination, just like in Drizzle's docs:

const result = await withPagination(qb, {
  page: 2,
  pageSize: 10
})
const result = await withPagination(qb, {
  page: 2,
  pageSize: 10
})


What's the cleanest way to use both of these helpers? Nesting them does technically work:

const result = await withPagination(
  withOrderBy(qb, {
    ...args
  }),
  {page: 2, pageSize: 10}
)
const result = await withPagination(
  withOrderBy(qb, {
    ...args
  }),
  {page: 2, pageSize: 10}
)


But that seems pretty hard to read and work with. Has anyone figured out a better way? Thank you!
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Dynamic query building
Drizzle TeamDTDrizzle Team / help
3y ago
Dynamic where query
Drizzle TeamDTDrizzle Team / help
3y ago
Double 'where' clause in dynamic query overriding the original 'where' clause not combining
Drizzle TeamDTDrizzle Team / help
15mo ago
Dynamic select() query builder
Drizzle TeamDTDrizzle Team / help
12mo ago