Get the last item when using --get with no ids/tags/meta.
This commit is contained in:
22
src/db.rs
22
src/db.rs
@@ -330,6 +330,28 @@ pub fn get_item(conn: &Connection, item_id: i64) -> Result<Option<Item>> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_item_last(conn: &Connection) -> Result<Option<Item>> {
|
||||
debug!("DB: Getting last item");
|
||||
let mut statement = conn
|
||||
.prepare_cached("
|
||||
SELECT id, ts, size, compression
|
||||
FROM items
|
||||
ORDER BY id DESC
|
||||
LIMIT 1")
|
||||
.context("Problem preparing SQL statement")?;
|
||||
|
||||
let mut rows = statement.query([])?;
|
||||
|
||||
match rows.next()? {
|
||||
Some(row) => Ok(Some(Item {
|
||||
id: row.get(0)?,
|
||||
ts: row.get(1)?,
|
||||
size: row.get(2)?,
|
||||
compression: row.get(3)?
|
||||
})),
|
||||
None => Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_item_tags(conn: &Connection, item: &Item) -> Result<Vec<Tag>> {
|
||||
debug!("DB: Getting tags for item: {:?}", item);
|
||||
|
||||
Reference in New Issue
Block a user