Skip to content

Commit 9e9ae46

Browse files
Add default argument for writeCheckpoint
1 parent 1545073 commit 9e9ae46

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 1.1.1 (unreleased)
4+
5+
* Added default `nil` value for `writeCheckpoint` parameter when calling `CrudBatch.complete()`. Developers no longer need to specify `nil` as an argument
6+
``` diff
7+
guard let finalBatch = try await powersync.getCrudBatch(limit: 100) else {
8+
return nil
9+
}
10+
- try await batch.complete(writeCheckpoint: nil)
11+
+ try await batch.complete()
12+
```
13+
314
## 1.1.0
415

516
* Add sync progress information through `SyncStatusData.downloadProgress`.

Sources/PowerSync/Protocol/db/CrudBatch.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,14 @@ public protocol CrudBatch {
1313
/// `writeCheckpoint` is optional.
1414
func complete(writeCheckpoint: String?) async throws
1515
}
16+
17+
public extension CrudBatch {
18+
/// Call to remove the changes from the local queue, once successfully uploaded.
19+
///
20+
/// `writeCheckpoint` is optional.
21+
func complete(writeCheckpoint: String? = nil) async throws {
22+
try await self.complete(
23+
writeCheckpoint: writeCheckpoint
24+
)
25+
}
26+
}

Tests/PowerSyncTests/CrudTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,25 @@ final class CrudTests: XCTestCase {
178178
}
179179

180180
XCTAssertNil(afterCompleteBatch)
181+
182+
try await database.writeTransaction { tx in
183+
for i in 0 ..< 100 {
184+
try tx.execute(
185+
sql: "INSERT INTO users (id, name, email, favorite_number) VALUES (uuid(), 'a', '[email protected]', ?)",
186+
parameters: [i]
187+
)
188+
}
189+
}
190+
191+
guard let finalBatch = try await database.getCrudBatch(limit: 100) else {
192+
return XCTFail("Failed to get crud batch")
193+
}
194+
XCTAssert(finalBatch.crud.count == 100)
195+
XCTAssert(finalBatch.hasMore == false)
196+
// Calling complete without a writeCheckpoint param should be possible
197+
try await finalBatch.complete()
198+
199+
let finalValidationBatch = try await database.getCrudBatch(limit: 100)
200+
XCTAssertNil(finalValidationBatch)
181201
}
182202
}

0 commit comments

Comments
 (0)