Skip to content

Commit 88204e7

Browse files
authored
Update core extension to 0.4.8 (#279)
* Update core extension to 0.4.8 * Prepare Kotlin release as well
1 parent 6bbfc78 commit 88204e7

File tree

9 files changed

+101
-13
lines changed

9 files changed

+101
-13
lines changed

CHANGELOG.md

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

3-
## 1.8.0 (unreleased)
3+
## 1.8.0
44

55
- Refactor SDK: `com.powersync:powersync-core` has an identical API, but now depends on
66
`com.powersync:powersync-common` where most logic is implemented.
77
- __POTENTIALLY BREAKING CHANGE__: If you were injecting a `DatabaseDriverFactory` into Koin or Dagger, note that the
88
`PowerSyncDatabase()` factory method now takes a more generic `PersistentConnectionFactory`.
99
- If you're using `PowerSyncDatabase.inMemory`, you explicitly have to import `com.powersync.inMemory` now.
10+
- Update the PowerSync core extension to version 0.4.8.
11+
- Add the `soft` flag to `disconnectAndClear()` which keeps an internal copy of synced data in the database, allowing
12+
faster re-sync if a compatible token is used in the next `connect()` call.
13+
- Add the `clear` parameter to `RawTable` to run a statement helping the core extension clear raw tables.
1014

1115
## 1.7.0
1216

common/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ val downloadPowersyncDesktopBinaries by tasks.registering(Download::class) {
3232
libs.versions.powersync.core
3333
.get()
3434
val linux_aarch64 =
35-
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/libpowersync_aarch64.so"
35+
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/libpowersync_aarch64.linux.so"
3636
val linux_x64 =
37-
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/libpowersync_x64.so"
37+
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/libpowersync_x64.linux.so"
3838
val macos_aarch64 =
39-
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/libpowersync_aarch64.dylib"
39+
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/libpowersync_aarch64.macos.dylib"
4040
val macos_x64 =
41-
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/libpowersync_x64.dylib"
41+
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/libpowersync_x64.macos.dylib"
4242
val windows_x64 =
4343
"https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v$coreVersion/powersync_x64.dll"
4444

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import com.powersync.db.ActiveDatabaseGroup
77
import com.powersync.db.crud.CrudEntry
88
import com.powersync.db.crud.CrudTransaction
99
import com.powersync.db.getString
10+
import com.powersync.db.schema.PendingStatement
11+
import com.powersync.db.schema.PendingStatementParameter
12+
import com.powersync.db.schema.RawTable
1013
import com.powersync.db.schema.Schema
14+
import com.powersync.sync.LegacySyncImplementation
1115
import com.powersync.test.getTempDir
1216
import com.powersync.test.waitFor
1317
import com.powersync.testutils.UserRow
@@ -548,4 +552,56 @@ class DatabaseTest {
548552
job.cancelAndJoin()
549553
hadOtherWrite.await()
550554
}
555+
556+
@Test
557+
fun testSoftClear() =
558+
databaseTest {
559+
database.execute("INSERT INTO users (id, name) VALUES (uuid(), ?)", listOf("testuser"))
560+
database.execute("INSERT INTO ps_buckets (name, last_applied_op) VALUES (?, ?)", listOf("bkt", 10))
561+
562+
// Doing a soft-clear should delete data but keep the bucket around.
563+
database.disconnectAndClear(soft = true)
564+
database.getAll("SELECT name FROM ps_buckets") { it.getString("name") } shouldHaveSize 1
565+
566+
// Doing a default clear also deletes buckets
567+
database.disconnectAndClear()
568+
database.getAll("SELECT name FROM ps_buckets") { it.getString("name") } shouldHaveSize 0
569+
}
570+
571+
@Test
572+
@OptIn(ExperimentalPowerSyncAPI::class)
573+
fun testRawTablesClear() =
574+
databaseTest(createInitialDatabase = false) {
575+
val db =
576+
openDatabase(
577+
Schema(
578+
listOf(
579+
RawTable(
580+
name = "lists",
581+
put =
582+
PendingStatement(
583+
"INSERT OR REPLACE INTO lists (id, name) VALUES (?, ?)",
584+
listOf(
585+
PendingStatementParameter.Id,
586+
PendingStatementParameter.Column("name"),
587+
),
588+
),
589+
delete =
590+
PendingStatement(
591+
"DELETE FROM lists WHERE id = ?",
592+
listOf(PendingStatementParameter.Id),
593+
),
594+
clear = "DELETE FROM lists",
595+
),
596+
),
597+
),
598+
)
599+
600+
db.execute("CREATE TABLE lists (id TEXT NOT NULL PRIMARY KEY, name TEXT)")
601+
db.execute("INSERT INTO lists (id, name) VALUES (uuid(), ?)", listOf("list"))
602+
603+
db.getAll("SELECT * FROM lists") { } shouldHaveSize 1
604+
db.disconnectAndClear()
605+
db.getAll("SELECT * FROM lists") { } shouldHaveSize 0
606+
}
551607
}

common/src/commonMain/kotlin/com/powersync/PowerSyncDatabase.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,26 @@ public interface PowerSyncDatabase : Queries {
204204

205205
/**
206206
* Disconnect and clear the database.
207-
* Use this when logging out.
207+
*
208+
* Clearing the database is useful when a user logs out, to ensure another user logging in later would not see
209+
* previous data.
210+
*
208211
* The database can still be queried after this is called, but the tables
209212
* would be empty.
210213
*
211214
* To preserve data in local-only tables, set clearLocal to false.
215+
*
216+
* A "soft" clear deletes publicly visible tables, but keeps internal copies of data synced in the database. This
217+
* usually means that if the same user logs out and back in again, the first sync is very fast because all internal
218+
* data is still available. When a different user logs in, no old data would be visible at any point.
219+
* Using soft deletes is recommended where it's not a security issue that old data could be reconstructible from the
220+
* database.
212221
*/
213222
@Throws(PowerSyncException::class, CancellationException::class)
214-
public suspend fun disconnectAndClear(clearLocal: Boolean = true)
223+
public suspend fun disconnectAndClear(
224+
clearLocal: Boolean = true,
225+
soft: Boolean = false,
226+
)
215227

216228
/**
217229
* Close the database, releasing resources.

common/src/commonMain/kotlin/com/powersync/db/PowerSyncDatabaseImpl.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,22 @@ internal class PowerSyncDatabaseImpl(
461461
}
462462
}
463463

464-
override suspend fun disconnectAndClear(clearLocal: Boolean) {
464+
override suspend fun disconnectAndClear(
465+
clearLocal: Boolean,
466+
soft: Boolean,
467+
) {
465468
disconnect()
466469

470+
var flags = 0
471+
if (clearLocal) {
472+
flags = flags or 1 // MASK_CLEAR_LOCAL
473+
}
474+
if (soft) {
475+
flags = flags or 2 // MASK_SOFT_CLEAR
476+
}
477+
467478
internalDb.writeTransaction { tx ->
468-
tx.getOptional("SELECT powersync_clear(?)", listOf(if (clearLocal) "1" else "0")) {}
479+
tx.getOptional("SELECT powersync_clear(?)", listOf(flags)) {}
469480
}
470481
currentStatus.update { copy(lastSyncedAt = null, hasSynced = false) }
471482
}

common/src/commonMain/kotlin/com/powersync/db/schema/RawTable.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public class RawTable(
3232
* The statement to run when the sync client wants to delete a row.
3333
*/
3434
public val delete: PendingStatement,
35+
/**
36+
* An optional statement to run when [com.powersync.PowerSyncDatabase.disconnectAndClear] is called on the database.
37+
*/
38+
public val clear: String? = null,
3539
) : BaseTable {
3640
override fun validate() {
3741
// We don't currently have any validation for raw tables
@@ -42,6 +46,7 @@ public class RawTable(
4246
put("name", name)
4347
put("put", put.serialize())
4448
put("delete", delete.serialize())
49+
clear?.let { put("clear", it) }
4550
}
4651
}
4752

common/src/jvmMain/kotlin/com/powersync/ExtractLib.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ internal fun extractLib(fileName: String): String {
99
val os = System.getProperty("os.name").lowercase()
1010
val (prefix, extension) =
1111
when {
12-
os.contains("nux") || os.contains("nix") || os.contains("aix") -> "lib" to "so"
13-
os.contains("mac") -> "lib" to "dylib"
12+
os.contains("nux") || os.contains("nix") || os.contains("aix") -> "lib" to "linux.so"
13+
os.contains("mac") -> "lib" to "macos.dylib"
1414
os.contains("win") -> "" to "dll"
1515
else -> error("Unsupported OS: $os")
1616
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ development=true
1919
RELEASE_SIGNING_ENABLED=true
2020
# Library config
2121
GROUP=com.powersync
22-
LIBRARY_VERSION=1.7.0
22+
LIBRARY_VERSION=1.8.0
2323
GITHUB_REPO=https://github.com/powersync-ja/powersync-kotlin.git
2424
# POM
2525
POM_URL=https://github.com/powersync-ja/powersync-kotlin/

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ serialization = "1.9.0"
1818
kotlinx-io = "0.8.0"
1919
ktor = "3.2.3"
2020
uuid = "0.8.4"
21-
powersync-core = "0.4.6"
21+
powersync-core = "0.4.8"
2222
turbine = "1.2.1"
2323
kotest = "5.9.1" # we can't upgrade to 6.x because that requires Java 11 or above (we need Java 8 support)
2424

0 commit comments

Comments
 (0)