sqlite: add helper to query single row

This commit is contained in:
Michael Mallan 2024-11-28 12:11:21 +00:00
parent 4f6dcbfdfd
commit da185361f9
No known key found for this signature in database
GPG Key ID: 5177CDCEDB0EABEB

View File

@ -50,6 +50,21 @@ where
.collect::<rusqlite::Result<Vec<T>>>()
}
/// Internal helper for queries boilerplate
pub fn db_query_row<P, F, T>(
conn: &mut rusqlite::Connection,
stmt_str: &str,
params: P,
f: F,
) -> Result<T, rusqlite::Error>
where
P: IntoIterator + rusqlite::Params,
P::Item: rusqlite::ToSql,
F: FnMut(&rusqlite::Row<'_>) -> rusqlite::Result<T>,
{
conn.prepare(stmt_str)?.query_row(params, f)
}
/// The current time as the number of seconds since the UNIX epoch, truncated to u32 since SQLite
/// only supports i64 integers.
pub fn curr_timestamp() -> u32 {