DT
Drizzle Team12mo ago
nk

$dynamic with multiple groupBy statements

Is there a way to do this? It seems that using more than one is overwriting the previous one. Example:
function withAGroupBy<T extends PgSelect>(query: T) {
return query
.leftJoin(...)
.groupBy(something1.id);
}
function withASecondGroupBy<T extends PgSelect>(query: T) {
return query
.leftJoin(...)
.groupBy(something2.id);
}

query = something.$dynamic;
withAGroupBy(query);
withASecondGroupBy(query);
function withAGroupBy<T extends PgSelect>(query: T) {
return query
.leftJoin(...)
.groupBy(something1.id);
}
function withASecondGroupBy<T extends PgSelect>(query: T) {
return query
.leftJoin(...)
.groupBy(something2.id);
}

query = something.$dynamic;
withAGroupBy(query);
withASecondGroupBy(query);
3 Replies
Angelelz
Angelelz12mo ago
Yeah, that's correct behavior. The drizzle way of achieving this, is composing your groupBy before, and then passing it to the query This functional approach will not work
nk
nkOP12mo ago
Probably hacky, but I just did
query.groupBy(...groupBy);
query.groupBy(...groupBy);
at the end of the code with the array being pushed whenever I include something. It would be a nice feature if it just automatically kept track of them though when it's dynamic.
Angelelz
Angelelz12mo ago
Not hacky, this is the drizzle way
Want results from more Discord servers?
Add your server