-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for json_agg_strict (PostgreSQL only) #892
base: v0.28
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
When using it with left join every field becomes nullable (I think that left join changes |
Hey 👋 Thanks! 🙏 I'm on the fence on this one for now:
const results = await db
.selectFrom("person")
.leftJoin("pet", "pet.owner_id", "person.id")
.groupBy("person.first_name")
.select((eb) => [
"first_name",
eb.fn
.coalesce( // <-- ensures defaults to empty array instead of null
eb.fn
.jsonAgg("pet")
.filterWhere("pet.owner_id", "is not", null), // <-- removes null rows
sql.lit("[]"),
)
.as("pets"),
])
.$narrowType<{ pets: Selectable<PetTable>[] }>() // <-- this makes all pet fields not nullable in a type-safe way.
.execute(); |
b9b80bc
to
f75bc1e
Compare
e32bb7f
to
ca11632
Compare
2b7007e
to
107076a
Compare
849d215
to
f5fddf5
Compare
Add support for json_agg_strict (PostgreSQL only) - this function is just like json_agg, but skips null (see https://www.postgresql.org/docs/current/functions-aggregate.html)
A few notes:
Thanks for this awesome package! :)