FEAT Can get a raw note.

TEST Asserts a non-existent raw note is non-existent.
This commit is contained in:
Elf M. Sternberg 2020-09-29 07:44:43 -07:00
parent 8ee71c76a3
commit 71dfc479d8
4 changed files with 35 additions and 3 deletions

View File

@ -11,13 +11,27 @@ mod tests {
use super::*;
use tokio;
#[tokio::test(threaded_scheduler)]
async fn it_works() {
async fn fresh_inmemory_database() -> NoteStore {
let storagepool = NoteStore::new("sqlite://:memory:").await;
assert!(storagepool.is_ok());
let storagepool = storagepool.unwrap();
assert!(storagepool.reset_database().await.is_ok());
storagepool
}
#[tokio::test(threaded_scheduler)]
async fn fetching_unfound_page_works() {
let storagepool = fresh_inmemory_database().await;
let unfoundpage = storagepool.fetch_page("nonexistent-page").await;
assert!(unfoundpage.is_err());
}
#[tokio::test(threaded_scheduler)]
async fn fetching_unfound_note_works() {
let storagepool = fresh_inmemory_database().await;
let unfoundnote = storagepool.fetch_note("nonexistent-note").await;
assert!(unfoundnote.is_err());
}
}

View File

@ -0,0 +1 @@
SELECT id, uuid, content, notetype FROM notes WHERE uuid=?;

View File

@ -2,7 +2,7 @@ use sqlx;
use sqlx::sqlite::SqlitePool;
use std::sync::Arc;
use crate::errors::NoteStoreError;
use crate::structs::RawPage;
use crate::structs::{RawPage, RawNote};
/// A handle to our Sqlite database.
#[derive(Clone)]
@ -34,4 +34,13 @@ impl NoteStore {
.fetch_one(&*self.0)
.await
}
pub async fn fetch_note(&self, id: &str) -> SqlResult<RawNote> {
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
}
}

View File

@ -8,3 +8,11 @@ pub struct RawPage {
title: String,
note_id: i64,
}
#[derive(Clone, Serialize, Deserialize, Debug, FromRow)]
pub struct RawNote {
id: i64,
uuid: String,
content: String,
notetype: String,
}