Skip to content

Commit

Permalink
feat: support adding filter after rpc call
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Nov 5, 2023
1 parent 1ec695b commit 108a30a
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 6 deletions.
66 changes: 66 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/PostgREST.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "PostgREST"
BuildableName = "PostgREST"
BlueprintName = "PostgREST"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "PostgREST"
BuildableName = "PostgREST"
BlueprintName = "PostgREST"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
8 changes: 4 additions & 4 deletions Sources/PostgREST/PostgrestClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ public actor PostgrestClient {
/// - params: The parameters to pass to the function call.
/// - count: Count algorithm to use to count rows returned by the function.
/// Only applicable for set-returning functions.
/// - Returns: A PostgrestTransformBuilder instance.
/// - Returns: A PostgrestFilterBuilder instance.
/// - Throws: An error if the function call fails.
public func rpc(
_ fn: String,
params: some Encodable,
count: CountOption? = nil
) throws -> PostgrestTransformBuilder {
) throws -> PostgrestFilterBuilder {
try PostgrestRpcBuilder(
configuration: configuration,
request: Request(path: "/rpc/\(fn)", method: .post, headers: configuration.headers)
Expand All @@ -130,12 +130,12 @@ public actor PostgrestClient {
/// - fn: The function name to call.
/// - count: Count algorithm to use to count rows returned by the function.
/// Only applicable for set-returning functions.
/// - Returns: A PostgrestTransformBuilder instance.
/// - Returns: A PostgrestFilterBuilder instance.
/// - Throws: An error if the function call fails.
public func rpc(
_ fn: String,
count: CountOption? = nil
) throws -> PostgrestTransformBuilder {
) throws -> PostgrestFilterBuilder {
try rpc(fn, params: NoParams(), count: count)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/PostgREST/PostgrestRpcBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public final class PostgrestRpcBuilder: PostgrestBuilder {
params: some Encodable,
head: Bool = false,
count: CountOption? = nil
) throws -> PostgrestTransformBuilder {
) throws -> PostgrestFilterBuilder {
// TODO: Support `HEAD` method
// https://github.com/supabase/postgrest-js/blob/master/src/lib/PostgrestRpcBuilder.ts#L38
assert(head == false, "HEAD is not currently supported yet.")
Expand All @@ -38,6 +38,6 @@ public final class PostgrestRpcBuilder: PostgrestBuilder {
}
}

return PostgrestTransformBuilder(self)
return PostgrestFilterBuilder(self)
}
}
3 changes: 3 additions & 0 deletions Tests/PostgRESTTests/BuildURLRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ final class BuildURLRequestTests: XCTestCase {
TestCase(name: "call rpc without parameter") { client in
try await client.rpc("test_fcn")
},
TestCase(name: "call rpc with filter") { client in
try await client.rpc("test_fcn").eq("id", value: 1)
},
TestCase(name: "test all filters and count") { client in
var query = await client.from("todos").select()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
curl \
--request POST \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--header "X-Client-Info: postgrest-swift/x.y.z" \
"https://example.supabase.co/rpc/test_fcn?id=eq.1"

0 comments on commit 108a30a

Please sign in to comment.