Skip to content

Commit 1b0155c

Browse files
feat(postgrest): use Date when filtering columns (#514)
* Add conformance to URLQueryRepresentable for Date * add test case --------- Co-authored-by: Guilherme Souza <[email protected]>
1 parent f6cd365 commit 1b0155c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Sources/PostgREST/URLQueryRepresentable.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ extension UUID: URLQueryRepresentable {
2727
public var queryValue: String { uuidString }
2828
}
2929

30+
extension Date: URLQueryRepresentable {
31+
public var queryValue: String {
32+
let formatter = ISO8601DateFormatter()
33+
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
34+
return formatter.string(from: self)
35+
}
36+
}
37+
3038
extension Array: URLQueryRepresentable where Element: URLQueryRepresentable {
3139
public var queryValue: String {
3240
"{\(map(\.queryValue).joined(separator: ","))}"

Tests/PostgRESTTests/BuildURLRequestTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ final class BuildURLRequestTests: XCTestCase {
222222
.select()
223223
.eq("to", value: "+16505555555")
224224
},
225+
TestCase(name: "filter using Date") { client in
226+
client.from("users")
227+
.select()
228+
.gt("created_at", value: Date(timeIntervalSince1970: 0))
229+
},
225230
]
226231

227232
for testCase in testCases {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
curl \
2+
--header "Accept: application/json" \
3+
--header "Content-Type: application/json" \
4+
--header "X-Client-Info: postgrest-swift/x.y.z" \
5+
"https://example.supabase.co/users?created_at=gt.1970-01-01T00:00:00.000Z&select=*"

0 commit comments

Comments
 (0)