diff --git a/Sources/PostgREST/PostgrestFilterBuilder.swift b/Sources/PostgREST/PostgrestFilterBuilder.swift index 7781eef7..6e23243e 100644 --- a/Sources/PostgREST/PostgrestFilterBuilder.swift +++ b/Sources/PostgREST/PostgrestFilterBuilder.swift @@ -22,9 +22,10 @@ public class PostgrestFilterBuilder: PostgrestTransformBuilder { return self } - public func or(_ filters: URLQueryRepresentable) -> PostgrestFilterBuilder { + public func or(_ filters: URLQueryRepresentable, referencedTable: String? = nil) -> PostgrestFilterBuilder { + let key = referencedTable.map { "\($0).or" } ?? "or" mutableState.withValue { - $0.request.query.append(URLQueryItem(name: "or", value: "(\(filters.queryValue.queryValue))")) + $0.request.query.append(URLQueryItem(name: key, value: "(\(filters.queryValue.queryValue))")) } return self } diff --git a/Tests/PostgRESTTests/BuildURLRequestTests.swift b/Tests/PostgRESTTests/BuildURLRequestTests.swift index 89b23c9a..1a0ae87b 100644 --- a/Tests/PostgRESTTests/BuildURLRequestTests.swift +++ b/Tests/PostgRESTTests/BuildURLRequestTests.swift @@ -123,6 +123,11 @@ final class BuildURLRequestTests: XCTestCase { .select() .contains("name", value: ["is:online", "faction:red"]) }, + TestCase(name: "test or filter with referenced table") { client in + await client.from("users") + .select("*, messages(*)") + .or("public.eq.true,recipient_id.eq.1", referencedTable: "messages") + }, TestCase(name: "test upsert not ignoring duplicates") { client in try await client.from("users") .upsert(User(email: "johndoe@supabase.io")) diff --git a/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.test-or-filter-with-referenced-table.txt b/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.test-or-filter-with-referenced-table.txt new file mode 100644 index 00000000..7f79742c --- /dev/null +++ b/Tests/PostgRESTTests/__Snapshots__/BuildURLRequestTests/testBuildRequest.test-or-filter-with-referenced-table.txt @@ -0,0 +1,5 @@ +curl \ + --header "Accept: application/json" \ + --header "Content-Type: application/json" \ + --header "X-Client-Info: postgrest-swift/x.y.z" \ + "https://example.supabase.co/users?messages.or=(public.eq.true,recipient_id.eq.1)&select=*,messages(*)" \ No newline at end of file