@@ -4,7 +4,7 @@ use core::{
44} ;
55
66use alloc:: {
7- collections:: btree_map:: { BTreeMap , Entry } ,
7+ collections:: btree_map:: BTreeMap ,
88 format,
99 rc:: Rc ,
1010 string:: { String , ToString } ,
@@ -73,7 +73,7 @@ impl InferredTableStructure {
7373 buffer. push_str ( " (id" ) ;
7474 for column in & self . columns {
7575 buffer. comma ( ) ;
76- buffer. push_str ( column) ;
76+ let _ = buffer. identifier ( ) . write_str ( column) ;
7777 }
7878 buffer. push_str ( ") VALUES (?" ) ;
7979 params. push ( PendingStatementValue :: Id ) ;
@@ -146,24 +146,22 @@ impl InferredSchemaCache {
146146 db : * mut sqlite:: sqlite3 ,
147147 schema_version : usize ,
148148 tbl : & RawTable ,
149- f : fn ( & mut SchemaCacheEntry ) -> Rc < PendingStatement > ,
149+ f : impl FnOnce ( & mut SchemaCacheEntry ) -> Rc < PendingStatement > ,
150150 ) -> Result < Rc < PendingStatement > , PowerSyncError > {
151151 let mut entries = self . entries . borrow_mut ( ) ;
152- let mut entry = entries. entry ( tbl. name . clone ( ) ) ;
153- let entry = match entry {
154- Entry :: Vacant ( entry) => entry. insert ( SchemaCacheEntry :: infer ( db, schema_version, tbl) ?) ,
155- Entry :: Occupied ( ref mut entry) => {
156- let value = entry. get_mut ( ) ;
157- if value. schema_version != schema_version {
158- // Values are outdated, refresh.
159- * value = SchemaCacheEntry :: infer ( db, schema_version, tbl) ?;
160- }
161-
162- value
152+ if let Some ( value) = entries. get_mut ( & tbl. name ) {
153+ if value. schema_version != schema_version {
154+ // Values are outdated, refresh.
155+ * value = SchemaCacheEntry :: infer ( db, schema_version, tbl) ?;
163156 }
164- } ;
165157
166- Ok ( f ( entry) )
158+ Ok ( f ( value) )
159+ } else {
160+ let mut entry = SchemaCacheEntry :: infer ( db, schema_version, tbl) ?;
161+ let stmt = f ( & mut entry) ;
162+ entries. insert ( tbl. name . clone ( ) , entry) ;
163+ Ok ( stmt)
164+ }
167165 }
168166}
169167
0 commit comments