Skip to content

Commit 7e1a6a7

Browse files
committed
AI code review
1 parent 8a7e3ad commit 7e1a6a7

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

crates/core/src/schema/raw_table.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::{
44
};
55

66
use alloc::{
7-
collections::btree_map::{BTreeMap, Entry},
7+
collections::btree_map::BTreeMap,
88
format,
99
rc::Rc,
1010
string::{String, ToString},
@@ -77,7 +77,7 @@ impl InferredTableStructure {
7777
buffer.push_str(" (id");
7878
for column in &self.columns {
7979
buffer.comma();
80-
buffer.push_str(column);
80+
let _ = buffer.identifier().write_str(column);
8181
}
8282
buffer.push_str(") VALUES (?");
8383
params.push(PendingStatementValue::Id);
@@ -150,24 +150,22 @@ impl InferredSchemaCache {
150150
db: *mut sqlite::sqlite3,
151151
schema_version: usize,
152152
tbl: &RawTable,
153-
f: fn(&mut SchemaCacheEntry) -> Rc<PendingStatement>,
153+
f: impl FnOnce(&mut SchemaCacheEntry) -> Rc<PendingStatement>,
154154
) -> Result<Rc<PendingStatement>, PowerSyncError> {
155155
let mut entries = self.entries.borrow_mut();
156-
let mut entry = entries.entry(tbl.name.clone());
157-
let entry = match entry {
158-
Entry::Vacant(entry) => entry.insert(SchemaCacheEntry::infer(db, schema_version, tbl)?),
159-
Entry::Occupied(ref mut entry) => {
160-
let value = entry.get_mut();
161-
if value.schema_version != schema_version {
162-
// Values are outdated, refresh.
163-
*value = SchemaCacheEntry::infer(db, schema_version, tbl)?;
164-
}
165-
166-
value
156+
if let Some(value) = entries.get_mut(&tbl.name) {
157+
if value.schema_version != schema_version {
158+
// Values are outdated, refresh.
159+
*value = SchemaCacheEntry::infer(db, schema_version, tbl)?;
167160
}
168-
};
169161

170-
Ok(f(entry))
162+
Ok(f(value))
163+
} else {
164+
let mut entry = SchemaCacheEntry::infer(db, schema_version, tbl)?;
165+
let stmt = f(&mut entry);
166+
entries.insert(tbl.name.clone(), entry);
167+
Ok(stmt)
168+
}
171169
}
172170
}
173171

crates/core/src/sync_local.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl<'a> SyncOperation<'a> {
132132

133133
self.collect_tables()?;
134134
let statement = self.collect_full_operations()?;
135+
// We're in a transaction, so the schem can't change while we're applying changes.
135136
let schema_version = InferredSchemaCache::current_schema_version(self.db)?;
136137
let schema_cache = &self.state.inferred_schema_cache;
137138

dart/test/sync_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ CREATE TRIGGER users_delete
11761176
final table = {
11771177
'name': 'users',
11781178
'table_name': 'local_users',
1179-
'local_only_columns': ['local'],
1179+
'synced_columns': ['name', 'email'],
11801180
// This also tests that the trigger preventing updates and deletes on
11811181
// insert-only tables is inert during sync_local.
11821182
'insert_only': true,

0 commit comments

Comments
 (0)