azteca69
azteca69
DTDrizzle Team
Created by azteca69 on 11/17/2023 in #help
How to filter null values from json_arrayagg
sql
6 replies
DTDrizzle Team
Created by Sphorb on 11/26/2023 in #help
server does not allow insecure connections, client must use SSL/TLS
No description
3 replies
DTDrizzle Team
Created by azteca69 on 11/17/2023 in #help
How to filter null values from json_arrayagg
It would be really helpful if someone can clarify if this is the right approach drizzle
6 replies
DTDrizzle Team
Created by azteca69 on 11/17/2023 in #help
How to filter null values from json_arrayagg
I actually found a way to filter them, but I am not sure if this is the best way
ctx.db
.select({
...getTableColumns(organizers),
ratings: {
rating: sql<number>`AVG(value)`,
reviews: sql<number>`COUNT(value)`,
},
pictures: sql<(typeof files.$inferSelect)[]>`
IF(COUNT(${files.id}) > 0,
JSON_ARRAYAGG(
JSON_OBJECT("id", ${files}.id, "name", ${files}.name, "url", ${files.url})
),
NULL)`.as("pictures"),
})
.from(organizers)
.leftJoin(files, eq(organizers.id, files.entityId))
.leftJoin(ratings, eq(organizers.id, ratings.organizerId))
.groupBy(organizers.id);
ctx.db
.select({
...getTableColumns(organizers),
ratings: {
rating: sql<number>`AVG(value)`,
reviews: sql<number>`COUNT(value)`,
},
pictures: sql<(typeof files.$inferSelect)[]>`
IF(COUNT(${files.id}) > 0,
JSON_ARRAYAGG(
JSON_OBJECT("id", ${files}.id, "name", ${files}.name, "url", ${files.url})
),
NULL)`.as("pictures"),
})
.from(organizers)
.leftJoin(files, eq(organizers.id, files.entityId))
.leftJoin(ratings, eq(organizers.id, ratings.organizerId))
.groupBy(organizers.id);
6 replies