Skip to main content

innate_core/storage/
meta.rs

1use super::*;
2
3impl Storage {
4    pub fn get_meta(&self, key: &str) -> Result<Option<String>> {
5        let mut stmt = self
6            .conn
7            .prepare_cached("SELECT value FROM meta WHERE key=?")?;
8        Ok(stmt.query_row([key], |r| r.get(0)).optional()?)
9    }
10
11    pub fn set_meta(&self, key: &str, value: &str) -> Result<()> {
12        self.conn.execute(
13            "INSERT OR REPLACE INTO meta(key, value) VALUES (?,?)",
14            params![key, value],
15        )?;
16        Ok(())
17    }
18
19    pub fn get_meta_or(&self, key: &str, default: &str) -> String {
20        self.get_meta(key)
21            .ok()
22            .flatten()
23            .unwrap_or_else(|| default.to_string())
24    }
25
26    // ------------------------------------------------------------------
27}