tusken
tusken copied to clipboard
Nested JSON objects/arrays from subqueries
db.select(
t.tweet(tweet => ({
// Many-to-one relation
author: db.get(t.user, tweet.author),
// Many-to-many relation
hashtags: db.select(t.hashtag).where(hashtag => hashtag.id.in(tweet.hashtags)),
// One-to-many relation
likes: db.select(t.like).where(like => like.tweet.eq(tweet.id)),
}))
)
That query would produce an array of objects with the following shape:
const result = {
author: { ... },
hashtags: [ { ... }, ... ],
likes: [ { ... }, ... ],
}
Marking this as low priority, since #14 covers the most poignant use cases.