Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Sources/PostgREST/PostgrestFilterBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions Tests/PostgRESTTests/BuildURLRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]"))
Expand Down
Original file line number Diff line number Diff line change
@@ -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(*)"