store done time

This commit is contained in:
əlemi 2022-03-21 00:44:55 +01:00
parent 0d5ca6bf58
commit 32eb53ba2b
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -46,7 +46,7 @@ pub fn open_sqlite_storage(path: &str) -> Result<SQLiteStorage, Error> {
id INTEGER PRIMARY KEY,
body TEXT NOT NULL,
due DATETIME,
done BOOL DEFAULT FALSE
done DATETIME DEFAULT NULL
);",
[],
)?;
@ -56,6 +56,7 @@ pub fn open_sqlite_storage(path: &str) -> Result<SQLiteStorage, Error> {
impl MemoStorage for SQLiteStorage {
fn all(&self, done: bool) -> Result<Vec<Memo>, Error> {
let mut results = Vec::new();
let not_null = if done { "NOT" } else { "" };
/*
* SQLite considers NULL as smallest value, so we will always get events with no due date
@ -65,9 +66,13 @@ impl MemoStorage for SQLiteStorage {
{
let mut statement = self.conn.prepare(
"SELECT * FROM memo WHERE due IS NOT NULL AND done = ? ORDER BY due, id",
format!(// TODO eww but I can't find a way to insert "NOT" with rusqlite
"SELECT * FROM memo WHERE due IS NOT NULL AND done IS {} NULL ORDER BY due, id",
not_null
)
.as_str(),
)?;
let mut rows = statement.query(params![done as u8])?;
let mut rows = statement.query([])?;
while let Some(row) = rows.next()? {
results.push(Memo {
@ -79,10 +84,14 @@ impl MemoStorage for SQLiteStorage {
}
{
let mut statement = self
.conn
.prepare("SELECT * FROM memo WHERE due IS NULL AND done = ? ORDER BY due, id")?;
let mut rows = statement.query(params![done as u8])?;
let mut statement = self.conn.prepare(
format!(// TODO eww but I can't find a way to insert "NOT" with rusqlite
"SELECT * FROM memo WHERE due IS NULL AND done IS {} NULL ORDER BY due, id",
not_null
)
.as_str(),
)?;
let mut rows = statement.query([])?;
while let Some(row) = rows.next()? {
results.push(Memo {
@ -125,7 +134,7 @@ impl MemoStorage for SQLiteStorage {
fn del(&self, id: u32) -> Result<bool, Error> {
let count = self
.conn
.execute("UPDATE memo SET done = 1 WHERE id = ?", params![id])?;
.execute("UPDATE memo SET done = ? WHERE id = ?", params![Utc::now(), id])?;
if count > 0 {
return Ok(true);
} else {