use super::database::Row;
use std::cell::RefCell;
pub struct Memory {
index: RefCell<Vec<Row>>,
}
impl Memory {
pub fn init() -> Self {
Self {
index: RefCell::new(Vec::new()),
}
}
pub fn push(&self, id: i64, query: String, is_default: bool) {
self.index.borrow_mut().push(Row {
id,
query,
is_default,
})
}
pub fn clear(&self) {
self.index.borrow_mut().clear()
}
pub fn records(&self) -> Vec<Row> {
self.index.borrow().clone()
}
pub fn default(&self) -> Option<Row> {
for record in self.index.borrow().iter() {
if record.is_default {
return Some(record.clone());
}
}
None
}
}