paginate logs
This commit is contained in:
13
src/logs.rs
13
src/logs.rs
@@ -33,10 +33,17 @@ impl LogEntry {
|
||||
))?;
|
||||
Ok(log)
|
||||
}
|
||||
pub fn get_all(conn: &Connection) -> Result<Vec<LogEntry>, DatabaseError> {
|
||||
pub fn total_count(conn: &Connection) -> Result<i64, DatabaseError> {
|
||||
Ok(conn.query_row("SELECT COUNT(*) FROM logs", (), |r| r.get(0))?)
|
||||
}
|
||||
pub fn get_chronological_offset(
|
||||
conn: &Connection,
|
||||
offset: i64,
|
||||
limit: i64,
|
||||
) -> Result<Vec<LogEntry>, DatabaseError> {
|
||||
Ok(conn
|
||||
.prepare("SELECT id, actor, target, actiontype, payload FROM logs ORDER BY id DESC")?
|
||||
.query_map((), |r| {
|
||||
.prepare("SELECT id, actor, target, actiontype, payload FROM logs ORDER BY id DESC LIMIT ?1 OFFSET ?2")?
|
||||
.query_map((limit, offset), |r| {
|
||||
let payload: String = r.get(4)?;
|
||||
Ok(LogEntry {
|
||||
id: r.get(0)?,
|
||||
|
||||
Reference in New Issue
Block a user