From ec81083aa91ea685fe1637214db8665d5e2f709d Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Tue, 10 Nov 2020 12:52:44 -0800 Subject: [PATCH] REFACTOR Moved the 'store' into its own module. --- server/nm-store/src/lib.rs | 1 - server/nm-store/src/store/mod.rs | 58 +++++++++++++++++++ .../{store_private.rs => store/private.rs} | 0 .../{ => store}/sql/initialize_database.sql | 0 .../select_notes_backreferencing_kasten.sql | 0 .../sql/select_notes_by_parameter.sql | 0 server/nm-store/src/{ => store}/store.rs | 4 +- 7 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 server/nm-store/src/store/mod.rs rename server/nm-store/src/{store_private.rs => store/private.rs} (100%) rename server/nm-store/src/{ => store}/sql/initialize_database.sql (100%) rename server/nm-store/src/{ => store}/sql/select_notes_backreferencing_kasten.sql (100%) rename server/nm-store/src/{ => store}/sql/select_notes_by_parameter.sql (100%) rename server/nm-store/src/{ => store}/store.rs (99%) diff --git a/server/nm-store/src/lib.rs b/server/nm-store/src/lib.rs index 014575b..e1e125b 100644 --- a/server/nm-store/src/lib.rs +++ b/server/nm-store/src/lib.rs @@ -1,7 +1,6 @@ mod errors; mod reference_parser; mod store; -mod store_private; mod structs; pub use crate::errors::NoteStoreError; diff --git a/server/nm-store/src/store/mod.rs b/server/nm-store/src/store/mod.rs new file mode 100644 index 0000000..40f08a5 --- /dev/null +++ b/server/nm-store/src/store/mod.rs @@ -0,0 +1,58 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +//! # Storage layer for Notesmachine +//! +//! This library implements the core functionality of Notesmachine and +//! describes that functionality to a storage layer. There's a bit of +//! intermingling in here which can't be helped, although it may make +//! sense in the future to separate the decomposition of the note +//! content into a higher layer. +//! +//! Notesmachine storage notes consist of two items: Note and Kasten. +//! This distinction is somewhat arbitrary, as structurally these two +//! items are stored in the same table. +//! +//! - Boxes have titles (and date metadata) +//! - Notes have content and a type (and date metadata) +//! - Notes are stored in boxes +//! - Notes are positioned with respect to other notes. +//! - There are two positions: +//! - Siblings, creating lists +//! - Children, creating trees like this one +//! - Notes may have references (pointers) to other boxes +//! - Notes may be moved around +//! - Notes may be deleted +//! - Boxes may be deleted +//! - When a box is renamed, every reference to that box is auto-edited to +//! reflect the change. If a box is renamed to match an existing box, the +//! notes in both boxes are merged. +//! +//! Note-to-note relationships form trees, and are kept in a SQL database of +//! (`parent_id`, `child_id`, `position`, `relationship_type`). The +//! `position` is a monotonic index on the parent (that is, every pair +//! (`parent_id`, `position`) must be unique). The `relationship_type` is +//! an enum and can specify that the relationship is *original*, +//! *embedding*, or *referencing*. An embedded or referenced note may be +//! read/write or read-only with respect to the original, but there is only +//! one original note at any time. +//! +//! Note-to-box relationships form a graph, and are kept in the SQL database +//! as a collection of *edges* from the note to the box (and naturally +//! vice-versa). +//! +//! - Decision: When an original note is deleted, do all references and +//! embeddings also get deleted, or is the oldest one elevated to be a new +//! "original"? Or is that something the user may choose? +//! +//! - Decision: Should the merging issue be handled at this layer, or would +//! it make sense to move this to a higher layer, and only provide the +//! hooks for it here? +//! + +mod private; +mod store; + +pub use crate::store::store::NoteResult; +pub use crate::store::store::NoteStore; diff --git a/server/nm-store/src/store_private.rs b/server/nm-store/src/store/private.rs similarity index 100% rename from server/nm-store/src/store_private.rs rename to server/nm-store/src/store/private.rs diff --git a/server/nm-store/src/sql/initialize_database.sql b/server/nm-store/src/store/sql/initialize_database.sql similarity index 100% rename from server/nm-store/src/sql/initialize_database.sql rename to server/nm-store/src/store/sql/initialize_database.sql diff --git a/server/nm-store/src/sql/select_notes_backreferencing_kasten.sql b/server/nm-store/src/store/sql/select_notes_backreferencing_kasten.sql similarity index 100% rename from server/nm-store/src/sql/select_notes_backreferencing_kasten.sql rename to server/nm-store/src/store/sql/select_notes_backreferencing_kasten.sql diff --git a/server/nm-store/src/sql/select_notes_by_parameter.sql b/server/nm-store/src/store/sql/select_notes_by_parameter.sql similarity index 100% rename from server/nm-store/src/sql/select_notes_by_parameter.sql rename to server/nm-store/src/store/sql/select_notes_by_parameter.sql diff --git a/server/nm-store/src/store.rs b/server/nm-store/src/store/store.rs similarity index 99% rename from server/nm-store/src/store.rs rename to server/nm-store/src/store/store.rs index 228a2c1..8161938 100644 --- a/server/nm-store/src/store.rs +++ b/server/nm-store/src/store/store.rs @@ -53,7 +53,7 @@ use crate::errors::NoteStoreError; use crate::reference_parser::build_references; -use crate::store_private::*; +use crate::store::private::*; use crate::structs::*; use sqlx::sqlite::SqlitePool; use std::cmp; @@ -64,7 +64,7 @@ use std::sync::Arc; #[derive(Clone, Debug)] pub struct NoteStore(Arc); -type NoteResult = core::result::Result; +pub type NoteResult = core::result::Result; // After wrestling for a while with the fact that 'box' is a reserved // word in Rust, I decided to just go with Note (note) and Kasten