Skip to content

Rename oldData in CRUD entries to previousValues #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Changelog

## unreleased
## 1.1.0

* Add `trackPreviousValues` option on `Table` which sets `CrudEntry.oldData` to previous values on updates.
* Add `trackPreviousValues` option on `Table` which sets `CrudEntry.previousValues` to previous values on updates.
* Add `trackMetadata` option on `Table` which adds a `_metadata` column that can be used for updates.
The configured metadata is available through `CrudEntry.metadata`.
* Add `ignoreEmptyUpdates` option which skips creating CRUD entries for updates that don't change any values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CrudTest {
database.execute("UPDATE lists SET name = ?", listOf("new name"))

val batch = database.getNextCrudTransaction()
batch!!.crud[0].oldData shouldBe mapOf("name" to "entry", "content" to "content")
batch!!.crud[0].previousValues shouldBe mapOf("name" to "entry", "content" to "content")
}

@Test
Expand All @@ -54,7 +54,7 @@ class CrudTest {
database.execute("UPDATE lists SET name = ?, content = ?", listOf("new name", "new content"))

val batch = database.getNextCrudTransaction()
batch!!.crud[0].oldData shouldBe mapOf("name" to "entry")
batch!!.crud[0].previousValues shouldBe mapOf("name" to "entry")
}

@Test
Expand All @@ -75,7 +75,7 @@ class CrudTest {
database.execute("UPDATE lists SET name = ?", listOf("new name"))

val batch = database.getNextCrudTransaction()
batch!!.crud[0].oldData shouldBe mapOf("name" to "entry")
batch!!.crud[0].previousValues shouldBe mapOf("name" to "entry")
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions core/src/commonMain/kotlin/com/powersync/db/crud/CrudEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public data class CrudEntry(
* These values can be tracked for `UPDATE` statements when [Table.trackPreviousValues] is
* enabled.
*/
val oldData: Map<String, String?>? = null,
val previousValues: Map<String, String?>? = null,
) {
public companion object {
public fun fromRow(row: CrudRow): CrudEntry {
Expand All @@ -80,7 +80,7 @@ public data class CrudEntry(
table = data["type"]!!.jsonPrimitive.content,
transactionId = row.txId,
metadata = data["metadata"]?.jsonPrimitive?.content,
oldData =
previousValues =
data["old"]?.jsonObject?.mapValues { (_, value) ->
value.jsonPrimitive.contentOrNull
},
Expand Down
6 changes: 3 additions & 3 deletions core/src/commonMain/kotlin/com/powersync/db/schema/Table.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public data class Table(
*/
val trackMetadata: Boolean = false,
/**
* When set to a non-null value, track old values of columns for [CrudEntry.oldData].
* When set to a non-null value, track old values of columns for [CrudEntry.previousValue].
*
* See [TrackPreviousValuesOptions] for details.
*/
Expand Down Expand Up @@ -219,7 +219,7 @@ public data class Table(
}

/**
* Options to include old values in [CrudEntry.oldData] for update statements.
* Options to include old values in [CrudEntry.previousValue] for update statements.
*
* These options are enabled by passing them to a non-local [Table] constructor.
*/
Expand All @@ -228,7 +228,7 @@ public data class TrackPreviousValuesOptions(
* A filter of column names for which updates should be tracked.
*
* When set to a non-null value, columns not included in this list will not appear in
* [CrudEntry.oldData]. By default, all columns are included.
* [CrudEntry.previousValues]. By default, all columns are included.
*/
val columnFilter: List<String>? = null,
/**
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ development=true
RELEASE_SIGNING_ENABLED=true
# Library config
GROUP=com.powersync
LIBRARY_VERSION=1.0.1
LIBRARY_VERSION=1.1.0
# The Swift KMM bridge artifacts are published to SPM via a unique tag version
# The version is the same as the LIBRARY_VERSION, but with a suffix of +SWIFT
# Please update this when updating the LIBRARY_VERSION
SWIFT_LIBRARY_VERSION=1.0.1+SWIFT
SWIFT_LIBRARY_VERSION=1.1.0+SWIFT
GITHUB_REPO=https://github.com/powersync-ja/powersync-kotlin.git
# POM
POM_URL=https://github.com/powersync-ja/powersync-kotlin/
Expand Down