TEST FAILING; the CTE isn't solid. Needs revision and testing.
This commit is contained in:
parent
fd4f39b5b8
commit
e429eaf93c
|
@ -19,7 +19,10 @@ pub struct RawPage {
|
||||||
pub struct RawNote {
|
pub struct RawNote {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub uuid: String,
|
pub uuid: String,
|
||||||
|
pub parent_id: i64,
|
||||||
|
pub parent_uuid: String,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
|
pub position: i64,
|
||||||
pub notetype: String,
|
pub notetype: String,
|
||||||
pub creation_date: DateTime<Utc>,
|
pub creation_date: DateTime<Utc>,
|
||||||
pub updated_date: DateTime<Utc>,
|
pub updated_date: DateTime<Utc>,
|
||||||
|
|
|
@ -56,9 +56,7 @@ FROM (
|
||||||
notes.deleted_date,
|
notes.deleted_date,
|
||||||
','||notes.id||',' -- Cycle monitor
|
','||notes.id||',' -- Cycle monitor
|
||||||
FROM notes
|
FROM notes
|
||||||
INNER JOIN pages ON pages.note_id = notes.id
|
WHERE notes.id = ? AND notes.notetype = "root"
|
||||||
WHERE
|
|
||||||
pages.slug = ? AND notes.notetype = "root"
|
|
||||||
|
|
||||||
-- RECURSIVE expression
|
-- RECURSIVE expression
|
||||||
UNION SELECT
|
UNION SELECT
|
||||||
|
|
|
@ -58,27 +58,28 @@ impl NoteStore {
|
||||||
/// that title is generated automatically.
|
/// that title is generated automatically.
|
||||||
pub async fn get_page_by_title(&self, title: &str) -> NoteResult<(RawPage, Vec<RawNote>)> {
|
pub async fn get_page_by_title(&self, title: &str) -> NoteResult<(RawPage, Vec<RawNote>)> {
|
||||||
let mut tx = self.0.begin().await?;
|
let mut tx = self.0.begin().await?;
|
||||||
let page = match select_page_by_title(&mut tx, title).await {
|
let (page, notes) = match select_page_by_title(&mut tx, title).await {
|
||||||
Ok(page) => page,
|
Ok(page) => {
|
||||||
|
let note_id = page.note_id;
|
||||||
|
(page, select_note_collection_from_root(&mut tx, note_id).await?)
|
||||||
|
}
|
||||||
Err(sqlx::Error::RowNotFound) => {
|
Err(sqlx::Error::RowNotFound) => {
|
||||||
let new_page = {
|
let page = {
|
||||||
let new_root_note = create_unique_root_note();
|
let new_root_note = create_unique_root_note();
|
||||||
let new_root_note_id = insert_one_new_note(&mut tx, &new_root_note).await?;
|
let new_root_note_id = insert_one_new_note(&mut tx, &new_root_note).await?;
|
||||||
let new_page_slug = generate_slug(&mut tx, title).await?;
|
let new_page_slug = generate_slug(&mut tx, title).await?;
|
||||||
let new_page = create_new_page_for(&title, &new_page_slug, new_root_note_id);
|
let new_page = create_new_page_for(&title, &new_page_slug, new_root_note_id);
|
||||||
let new_page_id = insert_one_new_page(&mut tx, &new_page).await?;
|
let _ = insert_one_new_page(&mut tx, &new_page).await?;
|
||||||
select_page_by_title(&mut tx, title).await
|
select_page_by_title(&mut tx, &title).await?
|
||||||
};
|
};
|
||||||
match new_page {
|
let note_id = page.note_id;
|
||||||
Ok(page) => page,
|
(page, select_note_collection_from_root(&mut tx, note_id).await?)
|
||||||
Err(e) => return Err(NoteStoreError::DBError(e)),
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Err(e) => return Err(NoteStoreError::DBError(e)),
|
Err(e) => return Err(NoteStoreError::DBError(e)),
|
||||||
};
|
};
|
||||||
// Todo: Replace vec with the results of the CTE
|
// Todo: Replace vec with the results of the CTE
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
return Ok((page, vec![]));
|
return Ok((page, notes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,12 +130,12 @@ where
|
||||||
.await?)
|
.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_note_collection_for_root<'a, E>(executor: E, root: i64) -> SqlResult<Vec<RawNote>>
|
async fn select_note_collection_from_root<'a, E>(executor: E, root: i64) -> SqlResult<Vec<RawNote>>
|
||||||
where
|
where
|
||||||
E: Executor<'a, Database = Sqlite>,
|
E: Executor<'a, Database = Sqlite>,
|
||||||
{
|
{
|
||||||
let select_note_collection_for_root = include_str!("sql/select_note_collection_from_root.sql");
|
let select_note_collection_from_root_sql = include_str!("sql/select_note_collection_from_root.sql");
|
||||||
Ok(sqlx::query_as(&select_note_collection_for_root)
|
Ok(sqlx::query_as(&select_note_collection_from_root_sql)
|
||||||
.bind(&root)
|
.bind(&root)
|
||||||
.fetch_all(executor)
|
.fetch_all(executor)
|
||||||
.await?)
|
.await?)
|
||||||
|
|
Loading…
Reference in New Issue