FEAT Can now retrieve and individual date by public ID.
This commit is contained in:
parent
2e08b02def
commit
6bc8b0e911
|
@ -42,20 +42,20 @@ mod tests {
|
|||
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");
|
||||
// }
|
||||
#[tokio::test(threaded_scheduler)]
|
||||
async fn can_save_a_note() {
|
||||
let storagepool = fresh_inmemory_database().await;
|
||||
let note_id = storagepool.insert_note("noteid", "notecontent", "note").await;
|
||||
assert!(note_id.is_ok(), format!("note is not ok: {:?}", note_id));
|
||||
let note_id = note_id.unwrap();
|
||||
assert!(note_id > 0);
|
||||
|
||||
let foundnote = storagepool.fetch_note("noteid").await;
|
||||
assert!(foundnote.is_ok(), format!("foundnote is not ok: {:?}", foundnote));
|
||||
let foundnote = foundnote.unwrap();
|
||||
assert_eq!(foundnote.content, "notecontent");
|
||||
assert_eq!(foundnote.notetype, "note");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ CREATE TABLE notes (
|
|||
creation_date DATETIME NOT NULL,
|
||||
updated_date DATETIME NOT NULL,
|
||||
lastview_date DATETIME NOT NULL,
|
||||
deleted_date DATETIME NOT NULL
|
||||
deleted_date DATETIME NULL
|
||||
);
|
||||
|
||||
CREATE INDEX notes_uuids ON notes (uuid);
|
||||
|
@ -25,7 +25,7 @@ CREATE TABLE pages (
|
|||
creation_date DATETIME NOT NULL,
|
||||
updated_date DATETIME NOT NULL,
|
||||
lastview_date DATETIME NOT NULL,
|
||||
deleted_date DATETIME NOT NULL,
|
||||
deleted_date DATETIME NULL,
|
||||
FOREIGN KEY (note_id) REFERENCES notes (id) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
INSERT INTO notes (
|
||||
uuid,
|
||||
content,
|
||||
notetype,
|
||||
creation_date,
|
||||
updated_date,
|
||||
lastview_date)
|
||||
VALUES (?, ?, ?, ?, ?, ?);
|
|
@ -1 +1 @@
|
|||
SELECT id, uuid, content, notetype FROM notes WHERE uuid=?;
|
||||
SELECT id, uuid, content, notetype, creation_date, updated_date, lastview_date, deleted_date FROM notes WHERE uuid=?;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::errors::NoteStoreError;
|
||||
use crate::structs::{RawNote, RawPage};
|
||||
use chrono;
|
||||
use sqlx;
|
||||
use sqlx::sqlite::SqlitePool;
|
||||
use std::sync::Arc;
|
||||
|
@ -34,4 +35,18 @@ impl NoteStore {
|
|||
let select_one_note_sql = include_str!("sql/select_one_note.sql");
|
||||
sqlx::query_as(select_one_note_sql).bind(&id).fetch_one(&*self.0).await
|
||||
}
|
||||
|
||||
pub async fn insert_note(&self, id: &str, content: &str, notetype: &str) -> SqlResult<i64> {
|
||||
let insert_one_note_sql = include_str!("sql/insert_one_note.sql");
|
||||
let now = chrono::Utc::now();
|
||||
Ok(sqlx::query(insert_one_note_sql)
|
||||
.bind(&id)
|
||||
.bind(&content)
|
||||
.bind(¬etype)
|
||||
.bind(&now)
|
||||
.bind(&now)
|
||||
.bind(&now)
|
||||
.execute(&*self.0).await?
|
||||
.last_insert_rowid())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,24 +4,24 @@ use sqlx::{self, FromRow};
|
|||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug, FromRow)]
|
||||
pub struct RawPage {
|
||||
id: i64,
|
||||
slug: String,
|
||||
title: String,
|
||||
note_id: i64,
|
||||
creation_date: DateTime<Utc>,
|
||||
updated_date: DateTime<Utc>,
|
||||
lastview_date: DateTime<Utc>,
|
||||
deleted_date: DateTime<Utc>,
|
||||
pub id: i64,
|
||||
pub slug: String,
|
||||
pub title: String,
|
||||
pub note_id: i64,
|
||||
pub creation_date: DateTime<Utc>,
|
||||
pub updated_date: DateTime<Utc>,
|
||||
pub lastview_date: DateTime<Utc>,
|
||||
pub deleted_date: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug, FromRow)]
|
||||
pub struct RawNote {
|
||||
id: i64,
|
||||
uuid: String,
|
||||
content: String,
|
||||
notetype: String,
|
||||
creation_date: DateTime<Utc>,
|
||||
updated_date: DateTime<Utc>,
|
||||
lastview_date: DateTime<Utc>,
|
||||
deleted_date: DateTime<Utc>,
|
||||
pub id: i64,
|
||||
pub uuid: String,
|
||||
pub content: String,
|
||||
pub notetype: String,
|
||||
pub creation_date: DateTime<Utc>,
|
||||
pub updated_date: DateTime<Utc>,
|
||||
pub lastview_date: DateTime<Utc>,
|
||||
pub deleted_date: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue