ยฉ 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Teamโ€ข3y agoโ€ข
8 replies
machour

Is there a way to modify the select() on an existing query ?

Let's say I have this query that I pass to a function

const query = db.select().from(myTable)
const query = db.select().from(myTable)


in my function, I'd like to clone the query, and modify its
select()
select()
clause to something like this:

.select({
   totalCount: sql<number>`COUNT(*)`,
})
.select({
   totalCount: sql<number>`COUNT(*)`,
})


Is this possible?

My current workaround is to inspect the
config
config
property on my query to create a new one, but I know that I shouldn't mess with internals:

      db.select({
        totalCount: sql<number>`COUNT(*)`,
      })
      // @ts-ignore since config is protected
      .from(query.config.table)
      db.select({
        totalCount: sql<number>`COUNT(*)`,
      })
      // @ts-ignore since config is protected
      .from(query.config.table)
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

Modified select() on an existing query example
Drizzle TeamDTDrizzle Team / help
3y ago
Is there a way to dynamically edit a query with the builder?
Drizzle TeamDTDrizzle Team / help
3y ago
Is there a way to properly type a "generic query"
Drizzle TeamDTDrizzle Team / help
8mo ago
Is there a way to save the generated response Type from a query?
Drizzle TeamDTDrizzle Team / help
3y ago