diff --git a/server/nm-store/Cargo.toml b/server/nm-store/Cargo.toml index d2debe5..79522cf 100644 --- a/server/nm-store/Cargo.toml +++ b/server/nm-store/Cargo.toml @@ -12,11 +12,13 @@ readme = "./README.org" [dependencies] thiserror = "1.0.20" -tokio = { version = "0.2.22", features = ["rt-threaded"] } +tokio = { version = "0.2.22", features = ["rt-threaded", "blocking"] } serde = { version = "1.0.116", features = ["derive"] } serde_json = "1.0.56" +chrono = { version = "0.4.18", features = ["serde"] } sqlx = { version = "0.4.0-beta.1", default-features = false, features = [ "runtime-tokio", + "chrono", "sqlite", "macros", ] } diff --git a/server/nm-store/src/lib.rs b/server/nm-store/src/lib.rs index 27bb446..b2afecc 100644 --- a/server/nm-store/src/lib.rs +++ b/server/nm-store/src/lib.rs @@ -41,4 +41,21 @@ mod tests { let unfoundnote = storagepool.fetch_note("nonexistent-note").await; assert!(unfoundnote.is_err()); } + +// #[tokio::test(threaded_scheduler)] +// async fn can_save_a_note() { +// let storagepool = fresh_inmemory_database().await; +// let note_id = storagepool.store_note("noteid", "notecontent", "note").await; +// assert!(note_id.is_ok()); +// let note_id = note_id.unwrap(); +// assert!(note_id > 0); +// +// let foundnote = storepool.fetch_note("noteid").await; +// assert!(foundnote.is_ok()); +// let foundnote = foundnote.unwrap(); +// assert_eq!(foundnote.content, "notecontent"); +// assert_eq!(foundnote.notetype, "note"); +// } + + } diff --git a/server/nm-store/src/sql/initialize_database.sql b/server/nm-store/src/sql/initialize_database.sql index d6a07c7..7bdd434 100644 --- a/server/nm-store/src/sql/initialize_database.sql +++ b/server/nm-store/src/sql/initialize_database.sql @@ -8,7 +8,11 @@ CREATE TABLE notes ( id INTEGER PRIMARY KEY AUTOINCREMENT, uuid TEXT NOT NULL UNIQUE, content TEXT NULL, - notetype TEXT + notetype TEXT, + creation_date DATETIME NOT NULL, + updated_date DATETIME NOT NULL, + lastview_date DATETIME NOT NULL, + deleted_date DATETIME NOT NULL ); CREATE INDEX notes_uuids ON notes (uuid); @@ -18,6 +22,10 @@ CREATE TABLE pages ( title text NOT NULL UNIQUE, slug text NOT NULL UNIQUE, note_id INTEGER, + creation_date DATETIME NOT NULL, + updated_date DATETIME NOT NULL, + lastview_date DATETIME NOT NULL, + deleted_date DATETIME NOT NULL, FOREIGN KEY (note_id) REFERENCES notes (id) ON DELETE NO ACTION ON UPDATE NO ACTION ); diff --git a/server/nm-store/src/structs.rs b/server/nm-store/src/structs.rs index 115f4ef..4ea89ba 100644 --- a/server/nm-store/src/structs.rs +++ b/server/nm-store/src/structs.rs @@ -1,3 +1,4 @@ +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use sqlx::{self, FromRow}; @@ -7,6 +8,10 @@ pub struct RawPage { slug: String, title: String, note_id: i64, + creation_date: DateTime, + updated_date: DateTime, + lastview_date: DateTime, + deleted_date: DateTime, } #[derive(Clone, Serialize, Deserialize, Debug, FromRow)] @@ -15,4 +20,8 @@ pub struct RawNote { uuid: String, content: String, notetype: String, + creation_date: DateTime, + updated_date: DateTime, + lastview_date: DateTime, + deleted_date: DateTime, }