show memos with expiration date first

This commit is contained in:
əlemi 2022-03-14 14:14:14 +01:00
parent 0feb69e7f4
commit f44d4db3cb
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -53,10 +53,18 @@ pub fn open_sqlite_storage(path: &str) -> Result<SQLiteStorage, Error> {
impl MemoStorage for SQLiteStorage { impl MemoStorage for SQLiteStorage {
fn all(&self) -> Result<Vec<Memo>, Error> { fn all(&self) -> Result<Vec<Memo>, Error> {
let mut statement = self.conn.prepare("SELECT * FROM memo ORDER BY due, id")?;
let mut rows = statement.query([])?;
let mut results = Vec::new(); let mut results = Vec::new();
/*
* SQLite considers NULL as smallest value, so we will always get events with no due date
* first. To circumvent this, we first query all memos with a due date, and then all
* others. This is kinda jank but will do for now.
*/
{
let mut statement = self.conn.prepare("SELECT * FROM memo WHERE due IS NOT NULL ORDER BY due, id")?;
let mut rows = statement.query([])?;
while let Some(row) = rows.next()? { while let Some(row) = rows.next()? {
results.push(Memo { results.push(Memo {
id: row.get(0)?, id: row.get(0)?,
@ -64,6 +72,20 @@ impl MemoStorage for SQLiteStorage {
due: row.get(2)?, due: row.get(2)?,
}); });
} }
}
{
let mut statement = self.conn.prepare("SELECT * FROM memo WHERE due IS NULL ORDER BY due, id")?;
let mut rows = statement.query([])?;
while let Some(row) = rows.next()? {
results.push(Memo {
id: row.get(0)?,
body: row.get(1)?,
due: row.get(2)?,
});
}
}
return Ok(results); return Ok(results);
} }