Skip to content

Commit 5acd01c

Browse files
committed
Merge remote-tracking branch 'origin/main' into schema-options
2 parents e4fdaca + c015326 commit 5acd01c

File tree

24 files changed

+898
-180
lines changed

24 files changed

+898
-180
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## unreleased
44

5+
* Fixed `CrudBatch` `hasMore` always returning false.
6+
* Added `triggerImmediately` to `onChange` method.
7+
* Report real-time progress information about downloads through `SyncStatus.downloadProgress`.
8+
* Compose: Add `composeState()` extension method on `SyncStatus`.
59
* Add `includeOld` option on `Table` which sets `CrudEntry.oldData` to previous values on updates.
610
* Add `includeMetadata` option on `Table` which adds a `_metadata` column that can be used for updates.
711
The configured metadata is available through `CrudEntry.metadata`.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.powersync.compose
2+
3+
import androidx.compose.runtime.Composable
4+
import androidx.compose.runtime.State
5+
import androidx.compose.runtime.collectAsState
6+
import com.powersync.sync.SyncStatus
7+
import com.powersync.sync.SyncStatusData
8+
9+
@Composable
10+
public fun SyncStatus.composeState(): State<SyncStatusData> = asFlow().collectAsState(initial = this)

core/src/commonIntegrationTest/kotlin/com/powersync/DatabaseTest.kt

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,22 @@ class DatabaseTest {
187187
fun testTableChangesUpdates() =
188188
databaseTest {
189189
turbineScope {
190-
val query = database.onChange(tables = setOf("users")).testIn(this)
190+
val query =
191+
database
192+
.onChange(
193+
tables = setOf("users"),
194+
).testIn(this)
191195

192196
database.execute(
193197
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
194198
listOf("Test", "[email protected]"),
195199
)
196200

197-
val changeSet = query.awaitItem()
201+
var changeSet = query.awaitItem()
202+
// The initial result
203+
changeSet.count() shouldBe 0
204+
205+
changeSet = query.awaitItem()
198206
changeSet.count() shouldBe 1
199207
changeSet.contains("users") shouldBe true
200208

@@ -418,4 +426,37 @@ class DatabaseTest {
418426

419427
database.getNextCrudTransaction() shouldBe null
420428
}
429+
430+
@Test
431+
fun testCrudBatch() =
432+
databaseTest {
433+
database.execute(
434+
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
435+
listOf("a", "[email protected]"),
436+
)
437+
438+
database.writeTransaction {
439+
it.execute(
440+
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
441+
listOf("b", "[email protected]"),
442+
)
443+
it.execute(
444+
"INSERT INTO users (id, name, email) VALUES (uuid(), ?, ?)",
445+
listOf("c", "[email protected]"),
446+
)
447+
}
448+
449+
// Purposely limit to less than the number of available ops
450+
var batch = database.getCrudBatch(2) ?: error("Batch should not be null")
451+
batch.hasMore shouldBe true
452+
batch.crud shouldHaveSize 2
453+
batch.complete(null)
454+
455+
batch = database.getCrudBatch(1000) ?: error("Batch should not be null")
456+
batch.crud shouldHaveSize 1
457+
batch.hasMore shouldBe false
458+
batch.complete(null)
459+
460+
database.getCrudBatch() shouldBe null
461+
}
421462
}

0 commit comments

Comments
 (0)