Skip to content

Commit bb92866

Browse files
authored
feat(postgrest): allow switching schema (#199)
* feat(postgrest): allow switching schema * test: add test for schema method
1 parent 5aeb803 commit bb92866

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

Sources/PostgREST/PostgrestClient.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,14 @@ public actor PostgrestClient {
134134
) throws -> PostgrestFilterBuilder {
135135
try rpc(fn, params: NoParams(), count: count)
136136
}
137+
138+
/// Select a schema to query or perform an function (rpc) call.
139+
///
140+
/// The schema needs to be on the list of exposed schemas inside Supabase.
141+
/// - Parameter schema: The schema to query.
142+
public func schema(_ schema: String) -> PostgrestClient {
143+
var configuration = configuration
144+
configuration.schema = schema
145+
return PostgrestClient(configuration: configuration)
146+
}
137147
}

Tests/PostgRESTTests/BuildURLRequestTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ final class BuildURLRequestTests: XCTestCase {
106106
.gt("received_at", value: "2023-03-23T15:50:30.511743+00:00")
107107
.order("received_at")
108108
},
109+
TestCase(name: "query non-default schema") { client in
110+
await client.schema("storage")
111+
.from("objects")
112+
.select()
113+
}
109114
]
110115

111116
for testCase in testCases {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
curl \
2+
--header "Accept: application/json" \
3+
--header "Accept-Profile: storage" \
4+
--header "Content-Type: application/json" \
5+
--header "X-Client-Info: postgrest-swift/x.y.z" \
6+
"https://example.supabase.co/objects?select=*"

0 commit comments

Comments
 (0)