Nacho Ruiz Martin
04/11/2024, 9:03 AMTable Event (id, name, stadium)
Table Stadium (id, name)`
//Pseudo SQL
SELECT * FROM Event e
INNER JOIN Stadium s
WHERE e.stadium = s.id
WHERE s.name ILIKE "query" <--- How to do this?
supabase.from("event").select() {
filter {
Event::stadium::name like "%la%" <- Not working
//or
like("stadium.name", "%la%") <- Working?
}
}
Jan
04/11/2024, 9:16 AMAnyType::property
is a different type than AnyType::property::nestedProperty
and there are no methods defined for that.
AnyType::property
is of type KProperty1<AnyType, T>
and AnyType::property::nestedProperty
only KProperty0<T>
So we would have to define similar methods like thisNacho Ruiz Martin
04/11/2024, 9:18 AMJan
04/11/2024, 9:22 AMstadium
Jan
04/11/2024, 11:35 AMColton Idle
04/11/2024, 3:05 PMNacho Ruiz Martin
04/11/2024, 3:10 PMNacho Ruiz Martin
04/11/2024, 3:10 PMColton Idle
04/11/2024, 3:11 PMNacho Ruiz Martin
04/11/2024, 3:11 PMNacho Ruiz Martin
04/11/2024, 3:32 PMNacho Ruiz Martin
04/11/2024, 4:48 PMreturn supabase
.from(tableName)
.select(
Columns.raw(
"""
id,
time,
league(*),
home_team!inner(*),
visitor_team!inner(*)
""".trimIndent().replace("\n", "")
)
) {
val pattern = "%$query%"
filter {
and {
Event::time gte todayAtMidnight
or {
ilike("home_team.name", pattern)
ilike("visitor_team.name", pattern)
}
}
}
}
.decodeList()
But the following error is thrown:
BadRequestRestException: "failed to parse logic tree ((time.gte.2024-04-11T00:00:00Z,or(home_team.name.ilike.%Gij%,visitor_team.name.ilike.%Gij%)))" (line 1, column 48) (unexpected "a" expecting "not" or operator (eq, gt, ...))
Jan
04/11/2024, 7:45 PMand
in your filter, because all filters must match by default. But this is not the error, the error is there because there is a .
in your logical expression filter (ilike("home_team.name")
). The dot is used for separating filters when in a logical expression, hence the error. Normally you would just specify the referencedTable
parameter (which doesn't exist for or
and and
I just realized, opened a PR), so you can filter foreign columns in a logical expression like this:
or(referencedTable = "home_team") {
ilike("name", pattern) //The name from home_team will be filtered on
}
however you have two different tables, I'm not sure if that would work even with the referencedTable
parameter.Jan
04/11/2024, 7:46 PMJan
04/11/2024, 7:48 PMNacho Ruiz Martin
04/12/2024, 7:55 AMsuch complex queriesIs it a complex query, though? Maybe I’m doing something odd since I’m not an expert in SQL by any means, but I just want to query a table and filter by a joined table’s column. Anyway, the database function sounds like a good idea 🙂. Thanks for that!
Nacho Ruiz Martin
04/13/2024, 10:58 AMNacho Ruiz Martin
04/13/2024, 12:59 PMor
, so the postgrest API doesn’t allow this.
A database function it is!