diff options
author | cel 🌸 <cel@blos.sm> | 2024-08-04 18:26:38 +0100 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2024-08-04 18:26:38 +0100 |
commit | c3fde18b74fa967a02b3a922a9a3554b80207b06 (patch) | |
tree | e2d822189e97c8600b5113490e6dc921f3398561 /src/db.rs | |
download | fj-c3fde18b74fa967a02b3a922a9a3554b80207b06.tar.gz fj-c3fde18b74fa967a02b3a922a9a3554b80207b06.tar.bz2 fj-c3fde18b74fa967a02b3a922a9a3554b80207b06.zip |
WIP: db
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!() + } +} |