Type support for porting Kysely jsonArrayFrom to Drizzle

I am trying to port this functionality from kysley to Drizzle, but I am struggling getting the typing to work. Kysely function:
export function jsonArrayFrom<O>(
expr: Expression<O>
): RawBuilder<Simplify<O>[]> {
return sql`(select coalesce(json_agg(agg), '[]') from ${expr} as agg)`
}
export function jsonArrayFrom<O>(
expr: Expression<O>
): RawBuilder<Simplify<O>[]> {
return sql`(select coalesce(json_agg(agg), '[]') from ${expr} as agg)`
}
Drizzle function:
export function jsonArrayFrom(subquery) {
return sql`(select coalesce(json_agg(agg), '[]') from ${subquery} as agg)`;
}
export function jsonArrayFrom(subquery) {
return sql`(select coalesce(json_agg(agg), '[]') from ${subquery} as agg)`;
}
Usage example:
ctx.db.select({
id: plan,
displayName: plan.displayName,
deductibles: jsonArrayFrom(ctx.db.select().from(deductible)),
}).from(plan)
ctx.db.select({
id: plan,
displayName: plan.displayName,
deductibles: jsonArrayFrom(ctx.db.select().from(deductible)),
}).from(plan)
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server