Skip to content

Commit 8ea3ded

Browse files
authored
Merge pull request #39 from appwrite/dev
Add time between queries
2 parents 3ef704f + 8550541 commit 8ea3ded

30 files changed

+1707
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies:
3333

3434
```swift
3535
dependencies: [
36-
.package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "11.0.0"),
36+
.package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "12.0.0"),
3737
],
3838
```
3939

Sources/Appwrite/Client.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ open class Client {
2121
"x-sdk-name": "Swift",
2222
"x-sdk-platform": "server",
2323
"x-sdk-language": "swift",
24-
"x-sdk-version": "11.0.0",
24+
"x-sdk-version": "12.0.0",
2525
"x-appwrite-response-format": "1.8.0"
2626
]
2727

Sources/Appwrite/Query.swift

Lines changed: 144 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ enum QueryValue: Codable {
66
case double(Double)
77
case bool(Bool)
88
case query(Query)
9+
case array([QueryValue]) // for nested arrays
910

1011
init(from decoder: Decoder) throws {
1112
let container = try decoder.singleValueContainer()
12-
// Attempt to decode each type
13+
1314
if let stringValue = try? container.decode(String.self) {
1415
self = .string(stringValue)
1516
} else if let intValue = try? container.decode(Int.self) {
@@ -20,8 +21,13 @@ enum QueryValue: Codable {
2021
self = .bool(boolValue)
2122
} else if let queryValue = try? container.decode(Query.self) {
2223
self = .query(queryValue)
24+
} else if let arrayValue = try? container.decode([QueryValue].self) {
25+
self = .array(arrayValue)
2326
} else {
24-
throw DecodingError.dataCorruptedError(in: container, debugDescription: "QueryValue cannot be decoded")
27+
throw DecodingError.dataCorruptedError(
28+
in: container,
29+
debugDescription: "QueryValue cannot be decoded"
30+
)
2531
}
2632
}
2733

@@ -38,6 +44,8 @@ enum QueryValue: Codable {
3844
try container.encode(value)
3945
case .query(let value):
4046
try container.encode(value)
47+
case .array(let value):
48+
try container.encode(value)
4149
}
4250
}
4351
}
@@ -85,6 +93,30 @@ public struct Query : Codable, CustomStringConvertible {
8593
return [.bool(boolValue)]
8694
case let queryValue as Query:
8795
return [.query(queryValue)]
96+
case let anyArray as [Any]:
97+
// Handle nested arrays
98+
let nestedValues = anyArray.compactMap { item -> QueryValue? in
99+
if let stringValue = item as? String {
100+
return .string(stringValue)
101+
} else if let intValue = item as? Int {
102+
return .int(intValue)
103+
} else if let doubleValue = item as? Double {
104+
return .double(doubleValue)
105+
} else if let boolValue = item as? Bool {
106+
return .bool(boolValue)
107+
} else if let queryValue = item as? Query {
108+
return .query(queryValue)
109+
} else if let nestedArray = item as? [Any] {
110+
// Convert nested array to QueryValue.array
111+
if let converted = convertToQueryValueArray(nestedArray) {
112+
return .array(converted)
113+
}
114+
return nil
115+
}
116+
return nil
117+
}
118+
return nestedValues.isEmpty ? nil : nestedValues
119+
88120
default:
89121
return nil
90122
}
@@ -354,6 +386,13 @@ public struct Query : Codable, CustomStringConvertible {
354386
).description
355387
}
356388

389+
public static func createdBetween(_ start: String, _ end: String) -> String {
390+
return Query(
391+
method: "createdBetween",
392+
values: [start, end]
393+
).description
394+
}
395+
357396
public static func updatedBefore(_ value: String) -> String {
358397
return Query(
359398
method: "updatedBefore",
@@ -368,6 +407,13 @@ public struct Query : Codable, CustomStringConvertible {
368407
).description
369408
}
370409

410+
public static func updatedBetween(_ start: String, _ end: String) -> String {
411+
return Query(
412+
method: "updatedBetween",
413+
values: [start, end]
414+
).description
415+
}
416+
371417
public static func or(_ queries: [String]) -> String {
372418
let decoder = JSONDecoder()
373419
let decodedQueries = queries.compactMap { queryStr -> Query? in
@@ -398,6 +444,102 @@ public struct Query : Codable, CustomStringConvertible {
398444
).description
399445
}
400446

447+
public static func distanceEqual(_ attribute: String, values: [Any], distance: Double, meters: Bool = true) -> String {
448+
return Query(
449+
method: "distanceEqual",
450+
attribute: attribute,
451+
values: [[values, distance, meters]]
452+
).description
453+
}
454+
455+
public static func distanceNotEqual(_ attribute: String, values: [Any], distance: Double, meters: Bool = true) -> String {
456+
return Query(
457+
method: "distanceNotEqual",
458+
attribute: attribute,
459+
values: [[values, distance, meters]]
460+
).description
461+
}
462+
463+
public static func distanceGreaterThan(_ attribute: String, values: [Any], distance: Double, meters: Bool = true) -> String {
464+
return Query(
465+
method: "distanceGreaterThan",
466+
attribute: attribute,
467+
values: [[values, distance, meters]]
468+
).description
469+
}
470+
471+
public static func distanceLessThan(_ attribute: String, values: [Any], distance: Double, meters: Bool = true) -> String {
472+
return Query(
473+
method: "distanceLessThan",
474+
attribute: attribute,
475+
values: [[values, distance, meters]]
476+
).description
477+
}
478+
479+
public static func intersects(_ attribute: String, values: [Any]) -> String {
480+
return Query(
481+
method: "intersects",
482+
attribute: attribute,
483+
values: [values]
484+
).description
485+
}
486+
487+
public static func notIntersects(_ attribute: String, values: [Any]) -> String {
488+
return Query(
489+
method: "notIntersects",
490+
attribute: attribute,
491+
values: [values]
492+
).description
493+
}
494+
495+
public static func crosses(_ attribute: String, values: [Any]) -> String {
496+
return Query(
497+
method: "crosses",
498+
attribute: attribute,
499+
values: [values]
500+
).description
501+
}
502+
503+
public static func notCrosses(_ attribute: String, values: [Any]) -> String {
504+
return Query(
505+
method: "notCrosses",
506+
attribute: attribute,
507+
values: [values]
508+
).description
509+
}
510+
511+
public static func overlaps(_ attribute: String, values: [Any]) -> String {
512+
return Query(
513+
method: "overlaps",
514+
attribute: attribute,
515+
values: [values]
516+
).description
517+
}
518+
519+
public static func notOverlaps(_ attribute: String, values: [Any]) -> String {
520+
return Query(
521+
method: "notOverlaps",
522+
attribute: attribute,
523+
values: [values]
524+
).description
525+
}
526+
527+
public static func touches(_ attribute: String, values: [Any]) -> String {
528+
return Query(
529+
method: "touches",
530+
attribute: attribute,
531+
values: [values]
532+
).description
533+
}
534+
535+
public static func notTouches(_ attribute: String, values: [Any]) -> String {
536+
return Query(
537+
method: "notTouches",
538+
attribute: attribute,
539+
values: [values]
540+
).description
541+
}
542+
401543
private static func parseValue(_ value: Any) -> [Any] {
402544
if let value = value as? [Any] {
403545
return value

Sources/Appwrite/Services/Account.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ open class Account: Service {
15481548
/// - Throws: Exception if the request fails
15491549
/// - Returns: AppwriteModels.Session
15501550
///
1551-
@available(*, deprecated, message: "This API has been deprecated.")
1551+
@available(*, deprecated, message: "This API has been deprecated since 1.6.0. Please use `Account.createSession` instead.")
15521552
open func updateMagicURLSession(
15531553
userId: String,
15541554
secret: String
@@ -1588,7 +1588,7 @@ open class Account: Service {
15881588
/// - Throws: Exception if the request fails
15891589
/// - Returns: AppwriteModels.Session
15901590
///
1591-
@available(*, deprecated, message: "This API has been deprecated.")
1591+
@available(*, deprecated, message: "This API has been deprecated since 1.6.0. Please use `Account.createSession` instead.")
15921592
open func updatePhoneSession(
15931593
userId: String,
15941594
secret: String

0 commit comments

Comments
 (0)