Skip to content

Commit

Permalink
feat: add is_local to SyncState
Browse files Browse the repository at this point in the history
  • Loading branch information
hydra-yse committed Nov 11, 2024
1 parent c935b6d commit 9862dc4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/core/src/persist/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ pub(crate) fn current_migrations() -> Vec<&'static str> {
"CREATE TABLE IF NOT EXISTS sync_state(
data_id TEXT NOT NULL PRIMARY KEY,
record_id TEXT NOT NULL UNIQUE,
record_revision INTEGER NOT NULL
record_revision INTEGER NOT NULL,
is_local bool NOT NULL DEFAULT 1
) STRICT;",
"CREATE TABLE IF NOT EXISTS sync_settings(
key TEXT NOT NULL PRIMARY KEY UNIQUE,
Expand Down
9 changes: 6 additions & 3 deletions lib/core/src/persist/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ impl Persister {
SELECT
data_id,
record_id,
record_revision
record_revision,
is_local
FROM sync_state
{where_clause_str}
"
Expand All @@ -32,6 +33,7 @@ impl Persister {
data_id,
record_id: row.get(1)?,
record_revision: row.get(2)?,
is_local: row.get(3)?,
}),
None => None,
})
Expand All @@ -56,13 +58,14 @@ impl Persister {

con.execute(
"
INSERT OR REPLACE INTO sync_state(data_id, record_id, record_revision)
VALUES (:data_id, :record_id, :record_revision)
INSERT OR REPLACE INTO sync_state(data_id, record_id, record_revision, is_local)
VALUES (:data_id, :record_id, :record_revision, :is_local)
",
named_params! {
":data_id": &sync_state.data_id,
":record_id": &sync_state.record_id,
":record_revision": &sync_state.record_revision,
":is_local": &sync_state.is_local,
},
)?;

Expand Down
1 change: 1 addition & 0 deletions lib/core/src/sync/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub(crate) struct SyncState {
pub(crate) data_id: String,
pub(crate) record_id: String,
pub(crate) record_revision: u64,
pub(crate) is_local: bool,
}

pub(crate) struct SyncSettings {
Expand Down

0 comments on commit 9862dc4

Please sign in to comment.