mirror of
https://git.alemi.dev/memo-cli.git
synced 2024-11-22 11:04:48 +01:00
show memos with expiration date first
This commit is contained in:
parent
0feb69e7f4
commit
f44d4db3cb
1 changed files with 30 additions and 8 deletions
|
@ -53,16 +53,38 @@ 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();
|
||||||
|
|
||||||
while let Some(row) = rows.next()? {
|
/*
|
||||||
results.push(Memo {
|
* SQLite considers NULL as smallest value, so we will always get events with no due date
|
||||||
id: row.get(0)?,
|
* first. To circumvent this, we first query all memos with a due date, and then all
|
||||||
body: row.get(1)?,
|
* others. This is kinda jank but will do for now.
|
||||||
due: row.get(2)?,
|
*/
|
||||||
});
|
|
||||||
|
{
|
||||||
|
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()? {
|
||||||
|
results.push(Memo {
|
||||||
|
id: row.get(0)?,
|
||||||
|
body: row.get(1)?,
|
||||||
|
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);
|
||||||
|
|
Loading…
Reference in a new issue