@@ -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 } ,
@@ -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
0 commit comments