|
|
|
@ -114,16 +114,16 @@ impl DatabaseEngine for Engine { |
|
|
|
fn create_new(engine: &Arc<Engine>, name: &str) -> Result<SqliteTable> { |
|
|
|
fn create_new(engine: &Arc<Engine>, name: &str) -> Result<SqliteTable> { |
|
|
|
engine.write_lock().execute(&format!("CREATE TABLE IF NOT EXISTS {} ( \"key\" BLOB PRIMARY KEY, \"value\" BLOB NOT NULL )", name), [])?; |
|
|
|
engine.write_lock().execute(&format!("CREATE TABLE IF NOT EXISTS {} ( \"key\" BLOB PRIMARY KEY, \"value\" BLOB NOT NULL )", name), [])?; |
|
|
|
|
|
|
|
|
|
|
|
SqliteTable { |
|
|
|
Ok(SqliteTable { |
|
|
|
engine: Arc::clone(engine), |
|
|
|
engine: Arc::clone(engine), |
|
|
|
name: name.to_owned(), |
|
|
|
name: name.to_owned(), |
|
|
|
watchers: RwLock::new(HashMap::new()), |
|
|
|
watchers: RwLock::new(HashMap::new()), |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Table mappings are `Weak` to prevent reference cycles, that creates this additional correctness logic.
|
|
|
|
// Table mappings are `Weak` to prevent reference cycles, that creates this additional correctness logic.
|
|
|
|
Ok(match self.tables.write().entry(name.to_string()) { |
|
|
|
Ok(match self.tables.write().entry(name.to_string()) { |
|
|
|
hash_map::Entry::Occupied(o) => { |
|
|
|
hash_map::Entry::Occupied(mut o) => { |
|
|
|
if let Some(table) = o.get().upgrade() { |
|
|
|
if let Some(table) = o.get().upgrade() { |
|
|
|
table |
|
|
|
table |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
@ -131,7 +131,7 @@ impl DatabaseEngine for Engine { |
|
|
|
|
|
|
|
|
|
|
|
let table = Arc::new(create_new(self, name)?); |
|
|
|
let table = Arc::new(create_new(self, name)?); |
|
|
|
|
|
|
|
|
|
|
|
o.insert(table.downgrade()); |
|
|
|
o.insert(Arc::downgrade(&table)); |
|
|
|
|
|
|
|
|
|
|
|
table |
|
|
|
table |
|
|
|
} |
|
|
|
} |
|
|
|
@ -139,7 +139,7 @@ impl DatabaseEngine for Engine { |
|
|
|
hash_map::Entry::Vacant(v) => { |
|
|
|
hash_map::Entry::Vacant(v) => { |
|
|
|
let table = Arc::new(create_new(self, name)?); |
|
|
|
let table = Arc::new(create_new(self, name)?); |
|
|
|
|
|
|
|
|
|
|
|
v.insert(table.downgrade()); |
|
|
|
v.insert(Arc::downgrade(&table)); |
|
|
|
|
|
|
|
|
|
|
|
table |
|
|
|
table |
|
|
|
} |
|
|
|
} |
|
|
|
|