Anshul
Anshul
DTDrizzle Team
Created by Anshul on 11/4/2024 in #help
How to select a subset of fields from a JSONB?
Thanks @rphlmr ⚡ that's exactly what I ended up with based on the feedback I was provided. Your GitHub gist had some really cool functions in it!
17 replies
DTDrizzle Team
Created by Anshul on 11/4/2024 in #help
How to select a subset of fields from a JSONB?
Thanks for finding and sharing this. Some pretty cool stuff here!
17 replies
DTDrizzle Team
Created by Anshul on 11/4/2024 in #help
How to select a subset of fields from a JSONB?
Expected return format
{ id, data: { agency, url } }
{ id, data: { agency, url } }
17 replies
DTDrizzle Team
Created by Anshul on 11/4/2024 in #help
How to select a subset of fields from a JSONB?
Thanks again @Angelelz. The above two syntaxes didn't work but the one below inspired by your reply actually worked. @rphlmr ⚡ would you be able to help here? Is there an easy way to not have to spell out each field individually?
select({
id: opp.id,
data: {
agency: sql<string>`opp.data->>'agency'`,
url: sql<string>`opp.data->>'url'`
}
})
select({
id: opp.id,
data: {
agency: sql<string>`opp.data->>'agency'`,
url: sql<string>`opp.data->>'url'`
}
})
This is from Supabase and it returns the selected fields keeping the data field as an object.
select(
`id, data->>agency, data->>url`
)
select(
`id, data->>agency, data->>url`
)
17 replies
DTDrizzle Team
Created by Anshul on 11/4/2024 in #help
How to select a subset of fields from a JSONB?
Tried this as well with no luck.
select(sql`id, data->>agency`)
select(sql`id, data->>agency`)
17 replies
DTDrizzle Team
Created by Anshul on 11/4/2024 in #help
How to select a subset of fields from a JSONB?
Thanks @Angelelz. I'm aware of the ->> operator which is how I handle this outside of Drizzle. I have several working examples of this but Drizzle doesn't seem to like this syntax. What am I doing wrong here assuming data is a JSONB type and the intention is to pull out just the agency field?
db.select({
id: opp.id,
data: `opp.data->>agency`
})
db.select({
id: opp.id,
data: `opp.data->>agency`
})
17 replies