You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanna create a dynamic select statement, adding different fields based on conditions. I copied an example from the docs, but the types don’t seem to work. How do you handle this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I wanna create a dynamic select statement, adding different fields based on conditions. I copied an example from the docs, but the types don’t seem to work. How do you handle this?
function withUser<T extends PgSelect>(qb: T) { return qb.leftJoin(schema.users, eq(schema.products.userId, schema.users.id)); }
let query = this.db.select().from(schema.products).limit(10).$dynamic();
if (params.includes.includes('user')) { query = withUser(query); }
Beta Was this translation helpful? Give feedback.
All reactions