K
Kysely•5mo ago
tzezar

Is there way to select every field from table using `select` instead of `selectAll`?

I have very wide table and writing every field by hand is time consuming. selectAll does the job, but I also need to populate some relations and build json_aggs. Is there way to either select every column from table (and then build jsonObject) or extend selectAll with some extra fields?
db
.selectFrom('document')
.select((eb)=> [
'dokument.*',
// some json_agg for example
])
.executeTakeFirstOrThrow()
db
.selectFrom('document')
.select((eb)=> [
'dokument.*',
// some json_agg for example
])
.executeTakeFirstOrThrow()
Using raw sql it could be done with
SELECT d*, json_obj(w*) as "warehouse"
FROM document d
LEFT JOIN warehouse w ON w.id = d.warehouse_id
SELECT d*, json_obj(w*) as "warehouse"
FROM document d
LEFT JOIN warehouse w ON w.id = d.warehouse_id
please dont waste your time on building this query, just a little hint will be super helpfull! 😉
Solution:
.selectAll('document')
.select(eb => ...)
.selectAll('document')
.select(eb => ...)
...
Jump to solution
1 Reply
Solution
koskimas
koskimas•5mo ago
.selectAll('document')
.select(eb => ...)
.selectAll('document')
.select(eb => ...)
Want results from more Discord servers?
Add your server