Whitespace

This commit is contained in:
Andrew Phillips
2023-09-08 17:18:16 +00:00
parent b50c75f007
commit e389617207

View File

@@ -54,7 +54,7 @@ pub struct Meta {
pub fn open(path: PathBuf) -> Result<Connection, Error> {
debug!("DB: Opening file: {:?}", path);
let mut conn = Connection::open_with_flags(path, OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE)
.context("Problem opening file")?;
.context("Problem opening file")?;
conn.pragma_update(None, "foreign_keys", "ON")
.context("Problem enabling SQLite foreign_keys pragma")?;
@@ -64,7 +64,7 @@ pub fn open(path: PathBuf) -> Result<Connection, Error> {
rusqlite::vtab::array::load_module(&conn)
.context("Problem enabling array module")?;
Ok(conn)
}
@@ -151,7 +151,7 @@ pub fn set_item_tags(conn: &Connection, item: Item, tags: &Vec<String>) -> Resul
name: tag_name.to_string()
})?;
}
Ok(())
}
@@ -163,7 +163,7 @@ pub fn query_all_items(conn: &Connection) -> Result<Vec<Item>> {
.context("Problem preparing SQL statement")?;
let mut rows = statement.query([])?;
let mut items = Vec::new();
while let Some(row) = rows.next()? {
let item = Item {
id: row.get(0)?,
@@ -173,7 +173,7 @@ pub fn query_all_items(conn: &Connection) -> Result<Vec<Item>> {
};
items.push(item);
}
Ok(items)
}
@@ -213,7 +213,7 @@ pub fn query_tagged_items<'a>(conn: &'a Connection, tags: &'a Vec<String>) -> Re
};
items.push(item);
}
Ok(items)
}
@@ -232,7 +232,7 @@ pub fn get_items_matching(conn: &Connection, tags: &Vec<String>, meta: &HashMap<
true => query_all_items(conn)?,
false => query_tagged_items(conn, tags)?
};
if meta.is_empty() {
debug!("DB: Not filtering on meta");
Ok(items)
@@ -245,15 +245,15 @@ pub fn get_items_matching(conn: &Connection, tags: &Vec<String>, meta: &HashMap<
for meta in get_item_meta(conn, item)? {
item_meta.insert(meta.name, meta.value);
}
debug!("DB: Matching: {:?}: {:?}", item, item_meta);
for (k, v) in meta.iter() {
match item_meta.get(k) {
Some(value) => item_ok = v.eq(value),
None => item_ok = false
}
if item_ok {
break;
}
@@ -265,7 +265,7 @@ pub fn get_items_matching(conn: &Connection, tags: &Vec<String>, meta: &HashMap<
}
Ok(filtered_items)
}
}
@@ -291,11 +291,11 @@ pub fn get_item_matching(conn: &Connection, tags: &Vec<String>, _meta: &HashMap<
.iter()
.map(|s| {rusqlite::types::Value::from(s.clone()) })
.collect();
let tags_ptr = Rc::new(tags_values);
let mut rows = statement.query((&tags_ptr, &tags.len()))?;
match rows.next()? {
Some(row) => Ok(Some(Item {
id: row.get(0)?,
@@ -318,7 +318,7 @@ pub fn get_item(conn: &Connection, item_id: i64) -> Result<Option<Item>> {
.context("Problem preparing SQL statement")?;
let mut rows = statement.query([item_id])?;
match rows.next()? {
Some(row) => Ok(Some(Item {
id: row.get(0)?,
@@ -361,7 +361,7 @@ pub fn get_item_tags(conn: &Connection, item: &Item) -> Result<Vec<Tag>> {
let mut rows = statement.query([item.id])?;
let mut tags = Vec::new();
while let Some(row) = rows.next()? {
tags.push(Tag {
id: row.get(0)?,
@@ -381,7 +381,7 @@ pub fn get_item_meta(conn: &Connection, item: &Item) -> Result<Vec<Meta>> {
let mut rows = statement.query([item.id])?;
let mut metas = Vec::new();
while let Some(row) = rows.next()? {
metas.push(Meta {
id: row.get(0)?,