diff options
Diffstat (limited to '')
-rw-r--r-- | src/db.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/db.rs b/src/db.rs new file mode 100644 index 0000000..dd35e4d --- /dev/null +++ b/src/db.rs @@ -0,0 +1,28 @@ +use sqlx::sqlite::SqlitePool; + +use crate::{task::Task, Result}; + +struct Db { + pool: SqlitePool, +} + +impl Db { + pub async fn create_task(&self, task: Task) -> Result<i64> { + let id = sqlx::query!( + "insert into tasks ( name, cron, archived, description ) values ( ?1, ?2, ?3, ?4 )", + task.name, + task.cron, + task.archived, + task.description + ) + .execute(&self.pool) + .await? + .last_insert_rowid(); + + Ok(id) + } + + pub async fn read_tasks(&self) -> Result<Vec<Task>> { + todo!() + } +} |