mirror of
https://git.alemi.dev/memo-cli.git
synced 2024-11-22 10:04:50 +01:00
store done time
This commit is contained in:
parent
0d5ca6bf58
commit
32eb53ba2b
1 changed files with 17 additions and 8 deletions
|
@ -46,7 +46,7 @@ pub fn open_sqlite_storage(path: &str) -> Result<SQLiteStorage, Error> {
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
body TEXT NOT NULL,
|
body TEXT NOT NULL,
|
||||||
due DATETIME,
|
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 {
|
impl MemoStorage for SQLiteStorage {
|
||||||
fn all(&self, done: bool) -> Result<Vec<Memo>, Error> {
|
fn all(&self, done: bool) -> Result<Vec<Memo>, Error> {
|
||||||
let mut results = Vec::new();
|
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
|
* 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(
|
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()? {
|
while let Some(row) = rows.next()? {
|
||||||
results.push(Memo {
|
results.push(Memo {
|
||||||
|
@ -79,10 +84,14 @@ impl MemoStorage for SQLiteStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut statement = self
|
let mut statement = self.conn.prepare(
|
||||||
.conn
|
format!(// TODO eww but I can't find a way to insert "NOT" with rusqlite
|
||||||
.prepare("SELECT * FROM memo WHERE due IS NULL AND done = ? ORDER BY due, id")?;
|
"SELECT * FROM memo WHERE due IS NULL AND done IS {} NULL ORDER BY due, id",
|
||||||
let mut rows = statement.query(params![done as u8])?;
|
not_null
|
||||||
|
)
|
||||||
|
.as_str(),
|
||||||
|
)?;
|
||||||
|
let mut rows = statement.query([])?;
|
||||||
|
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
results.push(Memo {
|
results.push(Memo {
|
||||||
|
@ -125,7 +134,7 @@ impl MemoStorage for SQLiteStorage {
|
||||||
fn del(&self, id: u32) -> Result<bool, Error> {
|
fn del(&self, id: u32) -> Result<bool, Error> {
|
||||||
let count = self
|
let count = self
|
||||||
.conn
|
.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 {
|
if count > 0 {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue