Skip to content

Commit cac2433

Browse files
authored
feat(database): add select on query result (#275)
1 parent b805cdc commit cac2433

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

Sources/PostgREST/PostgrestTransformBuilder.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public class PostgrestTransformBuilder: PostgrestBuilder {
2020
.joined(separator: "")
2121
mutableState.withValue {
2222
$0.request.query.append(URLQueryItem(name: "select", value: cleanedColumns))
23+
24+
if $0.request.headers["Prefer"] != nil {
25+
$0.request.headers["Prefer", default: ""] += ","
26+
}
27+
28+
$0.request.headers["Prefer", default: ""] += "return=representation"
2329
}
2430
return self
2531
}

Tests/PostgRESTTests/BuildURLRequestTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ final class BuildURLRequestTests: XCTestCase {
162162
.from("objects")
163163
.select()
164164
},
165+
TestCase(name: "select after an insert") { client in
166+
try await client.from("users")
167+
.insert(User(email: "[email protected]"))
168+
.select("id,email")
169+
}
165170
]
166171

167172
for testCase in testCases {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
curl \
2+
--request POST \
3+
--header "Accept: application/json" \
4+
--header "Content-Type: application/json" \
5+
--header "Prefer: return=representation" \
6+
--header "X-Client-Info: postgrest-swift/x.y.z" \
7+
--data "{\"email\":\"[email protected]\"}" \
8+
"https://example.supabase.co/users?select=id,email"

0 commit comments

Comments
 (0)