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