Skip to content

fix(postgrest): ensure Sendable conformance for execute method #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ iOSInjectionProject/
Secrets.swift
lcov.info
temp_coverage

.cursor/
12 changes: 8 additions & 4 deletions Sources/PostgREST/PostgrestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class PostgrestBuilder: @unchecked Sendable {
/// - options: Options for querying Supabase.
/// - Returns: A `PostgrestResponse<T>` instance representing the response.
@discardableResult
public func execute<T: Decodable>(
public func execute<T: Decodable & Sendable>(
options: FetchOptions = FetchOptions()
) async throws -> PostgrestResponse<T> {
try await execute(options: options) { [configuration] data in
Expand All @@ -93,7 +93,7 @@ public class PostgrestBuilder: @unchecked Sendable {
}
}

private func execute<T>(
private func execute<T: Sendable>(
options: FetchOptions,
decode: (Data) throws -> T
) async throws -> PostgrestResponse<T> {
Expand Down Expand Up @@ -126,7 +126,7 @@ public class PostgrestBuilder: @unchecked Sendable {

let response = try await http.send(request)

guard 200 ..< 300 ~= response.statusCode else {
guard 200..<300 ~= response.statusCode else {
if let error = try? configuration.decoder.decode(PostgrestError.self, from: response.data) {
throw error
}
Expand All @@ -135,7 +135,11 @@ public class PostgrestBuilder: @unchecked Sendable {
}

let value = try decode(response.data)
return PostgrestResponse(data: response.data, response: response.underlyingResponse, value: value)
return PostgrestResponse(
data: response.data,
response: response.underlyingResponse,
value: value
)
}
}

Expand Down
Loading