Skip to content

Commit c06aa18

Browse files
authored
feat: Add optional "referencedTable" parameter to OR PostGREST filter (#250)
1 parent 328430a commit c06aa18

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Sources/PostgREST/PostgrestFilterBuilder.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ public class PostgrestFilterBuilder: PostgrestTransformBuilder {
2222
return self
2323
}
2424

25-
public func or(_ filters: URLQueryRepresentable) -> PostgrestFilterBuilder {
25+
public func or(_ filters: URLQueryRepresentable, referencedTable: String? = nil) -> PostgrestFilterBuilder {
26+
let key = referencedTable.map { "\($0).or" } ?? "or"
2627
mutableState.withValue {
27-
$0.request.query.append(URLQueryItem(name: "or", value: "(\(filters.queryValue.queryValue))"))
28+
$0.request.query.append(URLQueryItem(name: key, value: "(\(filters.queryValue.queryValue))"))
2829
}
2930
return self
3031
}

Tests/PostgRESTTests/BuildURLRequestTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ final class BuildURLRequestTests: XCTestCase {
123123
.select()
124124
.contains("name", value: ["is:online", "faction:red"])
125125
},
126+
TestCase(name: "test or filter with referenced table") { client in
127+
await client.from("users")
128+
.select("*, messages(*)")
129+
.or("public.eq.true,recipient_id.eq.1", referencedTable: "messages")
130+
},
126131
TestCase(name: "test upsert not ignoring duplicates") { client in
127132
try await client.from("users")
128133
.upsert(User(email: "[email protected]"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
curl \
2+
--header "Accept: application/json" \
3+
--header "Content-Type: application/json" \
4+
--header "X-Client-Info: postgrest-swift/x.y.z" \
5+
"https://example.supabase.co/users?messages.or=(public.eq.true,recipient_id.eq.1)&select=*,messages(*)"

0 commit comments

Comments
 (0)