Skip to content

Commit eec1bbf

Browse files
Default Param for CrudBatch Complete (#47)
1 parent 1545073 commit eec1bbf

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
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+
* Improved `CrudBatch` and `CrudTransaction` `complete` function extensions. Developers no longer need to specify `nil` as an argument for `writeCheckpoint` when calling `CrudBatch.complete`. The base `complete` functions still accept an optional `writeCheckpoint` argument if developers use custom write checkpoints.
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ 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+
func complete() async throws {
20+
try await self.complete(
21+
writeCheckpoint: nil
22+
)
23+
}
24+
}

Sources/PowerSync/Protocol/db/CrudTransaction.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ public protocol CrudTransaction {
1818

1919
public extension CrudTransaction {
2020
/// Call to remove the changes from the local queue, once successfully uploaded.
21-
///
22-
/// `writeCheckpoint` is optional.
23-
func complete(writeCheckpoint: String? = nil) async throws {
21+
func complete() async throws {
2422
try await self.complete(
25-
writeCheckpoint: writeCheckpoint
23+
writeCheckpoint: nil
2624
)
2725
}
2826
}

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', 'a@example.com', ?)",
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)