Skip to content

Commit

Permalink
feat(database): add select on query result (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev authored Mar 22, 2024
1 parent b805cdc commit cac2433
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
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"

0 comments on commit cac2433

Please sign in to comment.