Skip to content

Commit b71eca4

Browse files
update demo and changelog
1 parent f23f364 commit b71eca4

File tree

4 files changed

+77
-13
lines changed

4 files changed

+77
-13
lines changed

CHANGELOG.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,74 @@
22

33
# 1.0.0-Beta.14
44

5-
- Removed references to the PowerSync Kotlin SDK from all public API protocols.
65
- Improved the stability of watched queries. Watched queries were previously susceptible to runtime crashes if an exception was thrown in the update stream. Errors are now gracefully handled.
76

7+
- Removed references to the PowerSync Kotlin SDK from all public API protocols. Dedicated Swift protocols are now defined. These protocols align better with Swift primitives.
8+
9+
- Database and transaction/lock level query `execute` methods now have `@discardableResult` annotation.
10+
11+
- `AttachmentContext`, `AttachmentQueue`, `AttachmentService` and `SyncingService` are are now explicitly declared as `open` classes, allowing them to be subclassed outside the defining module.
12+
13+
**BREAKING CHANGES**:
14+
15+
- Completing CRUD transactions or CRUD batches, in the `PowerSyncBackendConnector` `uploadData` handler, now has a simpler invocation.
16+
17+
```diff
18+
- _ = try await transaction.complete.invoke(p1: nil)
19+
+ try await transaction.complete()
20+
```
21+
22+
- `index` based `SqlCursor` getters now throw if the query result column value is `nil`. This is now consistent with the behaviour of named column getter operations. New `getXxxxxOptional(index: index)` methods are available if the query result value could be `nil`.
23+
24+
```diff
25+
let results = try transaction.getAll(
26+
sql: "SELECT * FROM my_table",
27+
parameters: [id]
28+
) { cursor in
29+
- cursor.getString(index: 0)!
30+
+ cursor.getStringOptional(index: 0)
31+
+ // OR
32+
+ // try cursor.getString(index: 0) // if the value should be required
33+
}
34+
```
35+
36+
- `SqlCursor` getters now directly return Swift types. `getLong` has been replaced with `getInt64`.
37+
38+
```diff
39+
let results = try transaction.getAll(
40+
sql: "SELECT * FROM my_table",
41+
parameters: [id]
42+
) { cursor in
43+
- cursor.getBoolean(index: 0)?.boolValue,
44+
+ cursor.getBooleanOptional(index: 0),
45+
- cursor.getLong(index: 0)?.int64Value,
46+
+ cursor.getInt64Optional(index: 0)
47+
+ // OR
48+
+ // try cursor.getInt64(index: 0) // if the value should be required
49+
}
50+
```
51+
52+
- Client parameters now need to be specified with strictly typed `JsonParam` enums.
53+
54+
```diff
55+
try await database.connect(
56+
connector: PowerSyncBackendConnector(),
57+
params: [
58+
- "foo": "bar"
59+
+ "foo": .string("bar")
60+
]
61+
)
62+
```
63+
64+
- `SyncStatus` values now use Swift primitives for status attributes. `lastSyncedAt` now is of `Date` type.
65+
66+
```diff
67+
- let lastTime: Date? = db.currentStatus.lastSyncedAt?.flatMap {
68+
- Date(timeIntervalSince1970: $0.epochSeconds)
69+
- }
70+
+ let time: Date? = db.currentStatus.lastSyncedAt
71+
```
72+
873
# 1.0.0-Beta.13
974

1075
- Update `powersync-kotlin` dependency to version `1.0.0-BETA32`, which includes:

Demo/PowerSyncExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/PowerSyncExample/PowerSync/SupabaseConnector.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,18 @@ class SupabaseConnector: PowerSyncBackendConnector {
101101

102102
switch entry.op {
103103
case .put:
104-
var data: [String: AnyCodable] = entry.opData?.mapValues { AnyCodable($0) } ?? [:]
105-
data["id"] = AnyCodable(entry.id)
104+
var data = entry.opData ?? [:]
105+
data["id"] = entry.id
106106
try await table.upsert(data).execute()
107107
case .patch:
108108
guard let opData = entry.opData else { continue }
109-
let encodableData = opData.mapValues { AnyCodable($0) }
110-
try await table.update(encodableData).eq("id", value: entry.id).execute()
109+
try await table.update(opData).eq("id", value: entry.id).execute()
111110
case .delete:
112111
try await table.delete().eq("id", value: entry.id).execute()
113112
}
114113
}
115114

116-
_ = try await transaction.complete.invoke(p1: nil)
115+
try await transaction.complete()
117116

118117
} catch {
119118
if let errorCode = PostgresFatalCodes.extractErrorCode(from: error),
@@ -127,7 +126,7 @@ class SupabaseConnector: PowerSyncBackendConnector {
127126
/// elsewhere instead of discarding, and/or notify the user.
128127
print("Data upload error: \(error)")
129128
print("Discarding entry: \(lastEntry!)")
130-
_ = try await transaction.complete.invoke(p1: nil)
129+
try await transaction.complete()
131130
return
132131
}
133132

Demo/PowerSyncExample/PowerSync/SystemManager.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ class SystemManager {
127127
sql: "SELECT photo_id FROM \(TODOS_TABLE) WHERE list_id = ? AND photo_id IS NOT NULL",
128128
parameters: [id]
129129
) { cursor in
130-
// FIXME Transactions should allow throwing in the mapper and should use generics correctly
131-
cursor.getString(index: 0) ?? "invalid" // :(
132-
} as? [String] // :(
130+
131+
try cursor.getString(index: 0)
132+
}
133133

134134
_ = try transaction.execute(
135135
sql: "DELETE FROM \(LISTS_TABLE) WHERE id = ?",
@@ -141,7 +141,7 @@ class SystemManager {
141141
parameters: [id]
142142
)
143143

144-
return attachmentIDs ?? [] // :(
144+
return attachmentIDs
145145
})
146146

147147
if let attachments {

0 commit comments

Comments
 (0)