Skip to content

Commit

Permalink
feat(postgrest): allow switching schema (#199)
Browse files Browse the repository at this point in the history
* feat(postgrest): allow switching schema

* test: add test for schema method
  • Loading branch information
grdsdev authored Dec 17, 2023
1 parent 5aeb803 commit bb92866
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Sources/PostgREST/PostgrestClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,14 @@ public actor PostgrestClient {
) throws -> PostgrestFilterBuilder {
try rpc(fn, params: NoParams(), count: count)
}

/// Select a schema to query or perform an function (rpc) call.
///
/// The schema needs to be on the list of exposed schemas inside Supabase.
/// - Parameter schema: The schema to query.
public func schema(_ schema: String) -> PostgrestClient {
var configuration = configuration
configuration.schema = schema
return PostgrestClient(configuration: configuration)
}
}
5 changes: 5 additions & 0 deletions Tests/PostgRESTTests/BuildURLRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ final class BuildURLRequestTests: XCTestCase {
.gt("received_at", value: "2023-03-23T15:50:30.511743+00:00")
.order("received_at")
},
TestCase(name: "query non-default schema") { client in
await client.schema("storage")
.from("objects")
.select()
}
]

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

0 comments on commit bb92866

Please sign in to comment.