Skip to content

Commit 549f04e

Browse files
author
DominicGBauer
committed
chore: final crud and bucket
1 parent 7aa52e0 commit 549f04e

File tree

5 files changed

+120
-0
lines changed

5 files changed

+120
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Foundation
2+
3+
enum OpType: Int, Codable {
4+
case clear = 1
5+
case move = 2
6+
case put = 3
7+
case remove = 4
8+
}
9+
10+
extension OpType: CustomStringConvertible {
11+
var description: String {
12+
return "\(self.rawValue)"
13+
}
14+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import Foundation
2+
3+
struct OplogEntry: Codable, Equatable {
4+
let checksum: Int64
5+
let opId: String
6+
let rowId: String?
7+
let rowType: String?
8+
let op: OpType.RawValue?
9+
let subkey: String?
10+
let data: String?
11+
12+
enum CodingKeys: String, CodingKey {
13+
case checksum
14+
case opId = "op_id"
15+
case rowId = "object_id"
16+
case rowType = "object_type"
17+
case op
18+
case subkey
19+
case data
20+
}
21+
22+
init(
23+
checksum: Int64,
24+
opId: String,
25+
rowId: String? = nil,
26+
rowType: String? = nil,
27+
op: OpType.RawValue? = nil,
28+
subkey: String? = nil,
29+
data: String? = nil
30+
) {
31+
self.checksum = checksum
32+
self.opId = opId
33+
self.rowId = rowId
34+
self.rowType = rowType
35+
self.op = op
36+
self.subkey = subkey
37+
self.data = data
38+
}
39+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Foundation
2+
3+
actor SharedPendingDeletesActor {
4+
private(set) var pendingBucketDeletes: Bool
5+
6+
init(initialValue: Bool = false) {
7+
self.pendingBucketDeletes = initialValue
8+
}
9+
10+
func setPendingBucketDeletes(_ value: Bool) {
11+
pendingBucketDeletes = value
12+
}
13+
14+
func getPendingBucketDeletes() -> Bool {
15+
return pendingBucketDeletes
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Foundation
2+
3+
struct WriteCheckpointResponse: Codable {
4+
let data: WriteCheckpointData
5+
}
6+
7+
struct WriteCheckpointData: Codable {
8+
let writeCheckpoint: String
9+
10+
enum CodingKeys: String, CodingKey {
11+
case writeCheckpoint = "write_checkpoint"
12+
}
13+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Foundation
2+
3+
/// Type of local change.
4+
public enum UpdateType {
5+
/// Insert or replace a row. All non-null columns are included in the data.
6+
case put
7+
8+
/// Update a row if it exists. All updated columns are included in the data.
9+
case patch
10+
11+
/// Delete a row if it exists.
12+
case delete
13+
14+
/// The JSON string representation of the update type
15+
private var json: String {
16+
switch self {
17+
case .put: return "PUT"
18+
case .patch: return "PATCH"
19+
case .delete: return "DELETE"
20+
}
21+
}
22+
23+
/// Convert the update type to its JSON string representation
24+
public func toJSON() -> String {
25+
return json
26+
}
27+
28+
/// Create an UpdateType from a JSON string, returning nil if the string doesn't match any known type
29+
public static func fromJSON(_ json: String) -> UpdateType? {
30+
switch json {
31+
case "PUT": return .put
32+
case "PATCH": return .patch
33+
case "DELETE": return .delete
34+
default: return nil
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)