Skip to content
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

feat(database): add select on query result #275

Merged
merged 1 commit into from
Mar 22, 2024
Merged
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
6 changes: 6 additions & 0 deletions Sources/PostgREST/PostgrestTransformBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public class PostgrestTransformBuilder: PostgrestBuilder {
.joined(separator: "")
mutableState.withValue {
$0.request.query.append(URLQueryItem(name: "select", value: cleanedColumns))

if $0.request.headers["Prefer"] != nil {
$0.request.headers["Prefer", default: ""] += ","
}

$0.request.headers["Prefer", default: ""] += "return=representation"
}
return self
}
Expand Down
5 changes: 5 additions & 0 deletions Tests/PostgRESTTests/BuildURLRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ final class BuildURLRequestTests: XCTestCase {
.from("objects")
.select()
},
TestCase(name: "select after an insert") { client in
try await client.from("users")
.insert(User(email: "[email protected]"))
.select("id,email")
}
]

for testCase in testCases {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
curl \
--request POST \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--header "Prefer: return=representation" \
--header "X-Client-Info: postgrest-swift/x.y.z" \
--data "{\"email\":\"[email protected]\"}" \
"https://example.supabase.co/users?select=id,email"
Loading