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)


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

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


Is this possible?

My current workaround is to inspect the 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)
Was this page helpful?