diff --git a/CHANGELOG.md b/CHANGELOG.md index 68b5b87..c13e378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 1.1.1 (unreleased) + +* 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. +``` diff +guard let finalBatch = try await powersync.getCrudBatch(limit: 100) else { + return nil +} +- try await batch.complete(writeCheckpoint: nil) ++ try await batch.complete() +``` + ## 1.1.0 * Add sync progress information through `SyncStatusData.downloadProgress`. diff --git a/Sources/PowerSync/Protocol/db/CrudBatch.swift b/Sources/PowerSync/Protocol/db/CrudBatch.swift index 6fb7fe8..c57b917 100644 --- a/Sources/PowerSync/Protocol/db/CrudBatch.swift +++ b/Sources/PowerSync/Protocol/db/CrudBatch.swift @@ -13,3 +13,12 @@ public protocol CrudBatch { /// `writeCheckpoint` is optional. func complete(writeCheckpoint: String?) async throws } + +public extension CrudBatch { + /// Call to remove the changes from the local queue, once successfully uploaded. + func complete() async throws { + try await self.complete( + writeCheckpoint: nil + ) + } +} diff --git a/Sources/PowerSync/Protocol/db/CrudTransaction.swift b/Sources/PowerSync/Protocol/db/CrudTransaction.swift index 3ce8147..eadc954 100644 --- a/Sources/PowerSync/Protocol/db/CrudTransaction.swift +++ b/Sources/PowerSync/Protocol/db/CrudTransaction.swift @@ -18,11 +18,9 @@ public protocol CrudTransaction { public extension CrudTransaction { /// Call to remove the changes from the local queue, once successfully uploaded. - /// - /// `writeCheckpoint` is optional. - func complete(writeCheckpoint: String? = nil) async throws { + func complete() async throws { try await self.complete( - writeCheckpoint: writeCheckpoint + writeCheckpoint: nil ) } } diff --git a/Tests/PowerSyncTests/CrudTests.swift b/Tests/PowerSyncTests/CrudTests.swift index c76d0c8..5b303d6 100644 --- a/Tests/PowerSyncTests/CrudTests.swift +++ b/Tests/PowerSyncTests/CrudTests.swift @@ -178,5 +178,25 @@ final class CrudTests: XCTestCase { } XCTAssertNil(afterCompleteBatch) + + try await database.writeTransaction { tx in + for i in 0 ..< 100 { + try tx.execute( + sql: "INSERT INTO users (id, name, email, favorite_number) VALUES (uuid(), 'a', 'a@example.com', ?)", + parameters: [i] + ) + } + } + + guard let finalBatch = try await database.getCrudBatch(limit: 100) else { + return XCTFail("Failed to get crud batch") + } + XCTAssert(finalBatch.crud.count == 100) + XCTAssert(finalBatch.hasMore == false) + // Calling complete without a writeCheckpoint param should be possible + try await finalBatch.complete() + + let finalValidationBatch = try await database.getCrudBatch(limit: 100) + XCTAssertNil(finalValidationBatch) } }