all property

hi. im getting this error. Property 'all' does not exist on type 'Omit<PgSelectBase<"
11 Replies
Angelelz
Angelelz9mo ago
There is no all method in postgres select.
Нарбек
Нарбек9mo ago
so there is no way to combine multiple foreign rows into an array?
Mykhailo
Mykhailo9mo ago
@Нарбек what do you want to accomplish? Could you please give more context?
Нарбек
Нарбек9mo ago
for example.
const data = await db
.select()
.from(users)
.leftJoin(orders, eq(orders.userId, users.id))
.all()
const data = await db
.select()
.from(users)
.leftJoin(orders, eq(orders.userId, users.id))
.all()
It's just an example. I can't use ORM syntax in my case i can't use ORM syntax because of this:
db.query.orders.findMany({
where: and(
ilike(
sql`${users.lastname} || ${users.firstname} || ${users.surname}` as any,
`%Alan%`
)
),
with: {
users: true,
},
})
db.query.orders.findMany({
where: and(
ilike(
sql`${users.lastname} || ${users.firstname} || ${users.surname}` as any,
`%Alan%`
)
),
with: {
users: true,
},
})
this filtering works when i use query builder syntax, but it doesn't when i use ORM syntax @solo orm syntax combines foreign rows into an array, but query builder syntax doesn't and thats why i needed all() method
Mykhailo
Mykhailo9mo ago
@Нарбек findMany handle the nesting of related records for you, resulting in a structured object with users nested within orders. When using a query builder, you get flat rows because SQL doesn't provide nesting by default. To get nested results, you'll need to manually process the rows and construct the nested objects.
Нарбек
Нарбек9mo ago
All method constructs the objects right? Will it be impemented for postgresql?
Mykhailo
Mykhailo9mo ago
As @Angelelz already said, there is no ‘all’ method in select . So I don’t know about its implementation
Angelelz
Angelelz9mo ago
You can make it work with this syntax you just need to use a subquery in the where
Нарбек
Нарбек9mo ago
I've used concat and raw ILIKE command but it doesn't work. Could you show working example of this kind of filtering please?
Angelelz
Angelelz9mo ago
db.query.orders.findMany({
where: inArray(
orders.userId,
db
.select({userId: users.id})
.from(users)
.where(and(
ilike(sql`${users.lastname} || ${users.firstname} || ${users.surname}` as any,`%Alan%`),
eq(users.id, orders.userId)
))
),
with: {
users: true,
},
})
db.query.orders.findMany({
where: inArray(
orders.userId,
db
.select({userId: users.id})
.from(users)
.where(and(
ilike(sql`${users.lastname} || ${users.firstname} || ${users.surname}` as any,`%Alan%`),
eq(users.id, orders.userId)
))
),
with: {
users: true,
},
})
I'm doing this from memory so take it with a grain of salt
Нарбек
Нарбек8mo ago
thanks
Want results from more Discord servers?
Add your server