My personal-knowledge-system, with deeply integrated task tracking and long term goal planning capabilities.
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat/dto: refactor db entities into DTO's.

Thanks for the cool ass name cainan

+154 -76
+14 -14
Cargo.lock
··· 1200 1200 ] 1201 1201 1202 1202 [[package]] 1203 - name = "db" 1204 - version = "0.1.0" 1205 - dependencies = [ 1206 - "anyhow", 1207 - "migration", 1208 - "rand 0.10.0", 1209 - "sea-orm", 1210 - "thiserror 2.0.18", 1211 - "tokio", 1212 - "tracing", 1213 - ] 1214 - 1215 - [[package]] 1216 1203 name = "deltae" 1217 1204 version = "0.3.2" 1218 1205 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1364 1351 checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" 1365 1352 1366 1353 [[package]] 1354 + name = "dto" 1355 + version = "0.1.0" 1356 + dependencies = [ 1357 + "anyhow", 1358 + "migration", 1359 + "rand 0.10.0", 1360 + "sea-orm", 1361 + "thiserror 2.0.18", 1362 + "tokio", 1363 + "tracing", 1364 + ] 1365 + 1366 + [[package]] 1367 1367 name = "dunce" 1368 1368 version = "1.0.5" 1369 1369 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1501 1501 "clap", 1502 1502 "color-eyre", 1503 1503 "crossterm", 1504 - "db", 1505 1504 "directories", 1505 + "dto", 1506 1506 "futures", 1507 1507 "human-panic", 1508 1508 "kdl",
+3 -3
Cargo.toml
··· 1 1 [workspace] 2 2 members = [ 3 - "crates/db", 4 - "crates/db/migration", 3 + "crates/dto", 4 + "crates/dto/migration", 5 5 "crates/tree" 6 6 ] 7 7 ··· 72 72 tracing-error = "0.2.1" 73 73 clap = { version = "4.5.60", features = ["derive", "cargo", "wrap_help", "unicode", "string", "unstable-styles"] } 74 74 kdl = "6.5.0" 75 - db = {path="./crates/db"} 75 + dto = {path="./crates/dto"} 76 76 77 77 [build-dependencies] 78 78 anyhow = "1.0.102"
+1 -1
crates/db/Cargo.toml crates/dto/Cargo.toml
··· 1 1 [package] 2 - name = "db" 2 + name = "dto" 3 3 version.workspace = true 4 4 edition.workspace = true 5 5 authors.workspace = true
crates/db/migration/Cargo.toml crates/dto/migration/Cargo.toml
crates/db/migration/README.md crates/dto/migration/README.md
crates/db/migration/src/lib.rs crates/dto/migration/src/lib.rs
crates/db/migration/src/m20260318_233726_group_table.rs crates/dto/migration/src/m20260318_233726_group_table.rs
crates/db/migration/src/m20260319_002245_task_table.rs crates/dto/migration/src/m20260319_002245_task_table.rs
crates/db/migration/src/main.rs crates/dto/migration/src/main.rs
crates/db/migration/src/types/mod.rs crates/dto/migration/src/types/mod.rs
crates/db/migration/src/types/nano_id.rs crates/dto/migration/src/types/nano_id.rs
crates/db/migration/src/types/priority.rs crates/dto/migration/src/types/priority.rs
crates/db/src/entity/group.rs crates/dto/src/entity/group.rs
-1
crates/db/src/entity/mod.rs crates/dto/src/entity/mod.rs
··· 1 1 //! `SeaORM` Entity, @generated by sea-orm-codegen 2.0 2 2 3 3 pub mod prelude; 4 - 5 4 pub mod group; 6 5 pub mod task; 7 6 pub mod zettel;
+1
crates/db/src/entity/prelude.rs crates/dto/src/entity/prelude.rs
··· 1 1 //! `SeaORM` Entity, @generated by sea-orm-codegen 2.0 2 + #![expect(unused_imports)] 2 3 3 4 pub use super::group::Entity as Group; 4 5 pub use super::task::Entity as Task;
crates/db/src/entity/task.rs crates/dto/src/entity/task.rs
crates/db/src/entity/zettel.rs crates/dto/src/entity/zettel.rs
-11
crates/db/src/errors.rs
··· 1 - use thiserror::Error; 2 - 3 - pub type DbResult<T> = Result<T, crate::errors::DbError>; 4 - 5 - #[derive(Debug, Error)] 6 - pub enum DbError { 7 - #[error("database file not found, tried looking at {not_found_at}")] 8 - NotFound { not_found_at: String }, 9 - #[error("Seaorm Error")] 10 - SeaOrm(#[from] sea_orm::error::DbErr), 11 - }
+12 -19
crates/db/src/lib.rs crates/dto/src/db.rs
··· 1 - //! The database abstraction for the different actions `Filaments` requires 2 - //! from a database service. 3 - 4 1 use std::path::PathBuf; 5 2 6 - use migration::{Migrator, MigratorTrait}; 3 + use migration::{Migrator, MigratorTrait as _}; 7 4 use sea_orm::{Database, DatabaseConnection}; 8 5 use tracing::debug; 9 6 10 - use crate::errors::{DbError, DbResult}; 11 - 12 - /// Database Errors 13 - mod errors; 14 - 15 - /// Database entities 16 - pub mod entity; 17 - 18 - /// Types defined in migration 19 - pub use migration::types::*; 20 - 21 - pub use sea_orm::ActiveValue; 22 - 23 - #[expect(unused_imports)] 24 - pub use errors::*; 7 + use thiserror::Error; 25 8 26 9 /// Database struct 27 10 #[derive(Debug)] 28 11 pub struct Db { 29 12 conn: DatabaseConnection, 13 + } 14 + 15 + pub type DbResult<T> = Result<T, DbError>; 16 + 17 + #[derive(Debug, Error)] 18 + pub enum DbError { 19 + #[error("database file not found, tried looking at {not_found_at}")] 20 + NotFound { not_found_at: String }, 21 + #[error("Seaorm Error")] 22 + SeaOrm(#[from] sea_orm::error::DbErr), 30 23 } 31 24 32 25 impl AsRef<DatabaseConnection> for Db {
+1 -1
crates/db/tests/common/mod.rs crates/dto/tests/common/mod.rs
··· 3 3 path::PathBuf, 4 4 }; 5 5 6 - use db::Db; 6 + use dto::Db; 7 7 use rand::RngExt; 8 8 9 9 pub async fn fresh_test_db() -> Db {
+14 -15
crates/db/tests/task.rs crates/dto/tests/task.rs
··· 1 1 //! Testing task functionality with the database abstraction. 2 2 3 - use db::entity::{group, prelude::*, zettel}; 4 - use db::{ActiveValue::Set, entity::task}; 5 - use sea_orm::ActiveModelTrait; 3 + use dto::{ 4 + ActiveModelTrait as _, ActiveValue::Set, GroupActiveModel, GroupEntity, GroupModel, 5 + TaskActiveModel, TaskEntity, TaskModel, ZettelActiveModel, ZettelEntity, ZettelModel, 6 + }; 6 7 mod common; 7 8 8 9 #[tokio::test] 9 10 async fn test_group_task_insert() { 10 11 let db = common::fresh_test_db().await; 11 12 12 - let group_zettel: zettel::Model = zettel::ActiveModel { 13 + let group_zettel: ZettelModel = ZettelActiveModel { 13 14 title: Set("Something".to_owned()), 14 15 file_path: Set("/voo/doo".to_owned()), 15 16 ..Default::default() ··· 18 19 .await 19 20 .unwrap(); 20 21 21 - let group: group::Model = group::ActiveModel { 22 + let group: GroupModel = GroupActiveModel { 22 23 name: Set("something".to_owned()), 23 24 color: Set("color".to_owned()), 24 25 zettel_id: Set(group_zettel.nano_id.clone()), ··· 28 29 .await 29 30 .unwrap(); 30 31 31 - let task_zettel: zettel::Model = zettel::ActiveModel { 32 + let task_zettel: ZettelModel = ZettelActiveModel { 32 33 // nano_id: Set(NanoId::default()), 33 34 title: Set("nomething".to_owned()), 34 35 file_path: Set("/voo/doo".to_owned()), ··· 38 39 .await 39 40 .unwrap(); 40 41 41 - let task: task::Model = task::ActiveModel { 42 + let task: TaskModel = TaskActiveModel { 42 43 name: Set("something".to_owned()), 43 44 group_id: Set(group.nano_id.to_owned()), 44 45 zettel_id: Set(task_zettel.nano_id.clone()), ··· 48 49 .await 49 50 .unwrap(); 50 51 51 - let task = Task::load() 52 + let task = TaskEntity::load() 52 53 .filter_by_nano_id(task.nano_id.clone()) 53 - .with(Group) 54 - .with(Zettel) 54 + .with(GroupEntity) 55 + .with(ZettelEntity) 55 56 .one(db.as_ref()) 56 57 .await 57 58 .unwrap() 58 59 .unwrap(); 59 60 60 - let group = Group::load() 61 + let group = GroupEntity::load() 61 62 .filter_by_nano_id(group.nano_id.clone()) 62 - .with(Task) 63 - .with(Zettel) 63 + .with(TaskEntity) 64 + .with(ZettelEntity) 64 65 .one(db.as_ref()) 65 66 .await 66 67 .unwrap() ··· 68 69 69 70 println!("group: {group:#?}"); 70 71 println!("task: {task:#?}"); 71 - 72 - panic!() 73 72 }
+58
crates/dto/migration/src/m20260323_002518_zettel_table.rs
··· 1 + use sea_orm_migration::{prelude::*, schema::*}; 2 + 3 + use crate::types::NANO_ID_LEN; 4 + 5 + #[derive(DeriveMigrationName)] 6 + pub struct Migration; 7 + 8 + #[async_trait::async_trait] 9 + impl MigrationTrait for Migration { 10 + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { 11 + manager 12 + .create_table( 13 + Table::create() 14 + .table(Zettel::Table) 15 + .if_not_exists() 16 + .col(pk_auto(Zettel::Id)) 17 + .col( 18 + string(Zettel::NanoId) 19 + .string_len(NANO_ID_LEN as u32) 20 + .unique_key() 21 + .not_null(), 22 + ) 23 + .col(string(Zettel::Title).not_null()) 24 + .col(string(Zettel::FilePath).not_null()) 25 + .to_owned(), 26 + ) 27 + .await?; 28 + 29 + manager 30 + .create_index( 31 + Index::create() 32 + .name("idx_zettel_pub_id") 33 + .table(Zettel::Table) 34 + .col(Zettel::NanoId) 35 + .to_owned(), 36 + ) 37 + .await 38 + } 39 + 40 + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { 41 + manager 42 + .drop_index(Index::drop().name("idx_zettel_pub_id").to_owned()) 43 + .await?; 44 + 45 + manager 46 + .drop_table(Table::drop().table("post").to_owned()) 47 + .await 48 + } 49 + } 50 + 51 + #[derive(DeriveIden)] 52 + pub enum Zettel { 53 + Table, 54 + Id, 55 + NanoId, 56 + Title, 57 + FilePath, 58 + }
+39
crates/dto/src/lib.rs
··· 1 + //! The DTO's (Data Transfer Objects) used to interact with 2 + //! the Database. There is also a simple database struct in here. 3 + 4 + /// Database and its Errors 5 + mod db; 6 + pub use db::*; 7 + 8 + /// exported traits for the database 9 + pub use sea_orm::ActiveModelTrait; 10 + pub use sea_orm::ActiveValue; 11 + 12 + /// Exporting this as a generic NanoId. 13 + pub use migration::types::NanoId; 14 + /// Exporting this as DTO so we can newtype this in a later crate 15 + /// and add additional functionality to it. 16 + pub use migration::types::Priority as PriorityDTO; 17 + 18 + mod entity; 19 + 20 + /// Everything related to groups. 21 + pub use entity::group::ActiveModel as GroupActiveModel; 22 + pub use entity::group::ActiveModelEx as GroupActiveModelEx; 23 + pub use entity::group::Entity as GroupEntity; 24 + pub use entity::group::Model as GroupModel; 25 + pub use entity::group::ModelEx as GroupModelEx; 26 + 27 + /// Everything related to tasks. 28 + pub use entity::task::ActiveModel as TaskActiveModel; 29 + pub use entity::task::ActiveModelEx as TaskActiveModelEx; 30 + pub use entity::task::Entity as TaskEntity; 31 + pub use entity::task::Model as TaskModel; 32 + pub use entity::task::ModelEx as TaskModelEx; 33 + 34 + /// Everything related to zetetl's. 35 + pub use entity::zettel::ActiveModel as ZettelActiveModel; 36 + pub use entity::zettel::ActiveModelEx as ZettelActiveModelEx; 37 + pub use entity::zettel::Entity as ZettelEntity; 38 + pub use entity::zettel::Model as ZettelModel; 39 + pub use entity::zettel::Model as ZettelModelEx;
+11 -11
flake.lock
··· 8 8 "rust-analyzer-src": "rust-analyzer-src" 9 9 }, 10 10 "locked": { 11 - "lastModified": 1774163246, 12 - "narHash": "sha256-gzlqyLjP44LWraUd3Zn4xrQKOtK+zcBJ77pnsSUsxcM=", 11 + "lastModified": 1774555695, 12 + "narHash": "sha256-JpTx7Rn8sILuXAH9a0K0UCZST5KY9ZTMzrZ61KcsNno=", 13 13 "owner": "nix-community", 14 14 "repo": "fenix", 15 - "rev": "4cd28929c68cae521589bc21958d3793904ed1e2", 15 + "rev": "d76ca95395662ed18b02b894e487eb41fd0e7d99", 16 16 "type": "github" 17 17 }, 18 18 "original": { ··· 23 23 }, 24 24 "nixpkgs": { 25 25 "locked": { 26 - "lastModified": 1773821835, 27 - "narHash": "sha256-TJ3lSQtW0E2JrznGVm8hOQGVpXjJyXY2guAxku2O9A4=", 28 - "rev": "b40629efe5d6ec48dd1efba650c797ddbd39ace0", 29 - "revCount": 964859, 26 + "lastModified": 1774386573, 27 + "narHash": "sha256-4hAV26quOxdC6iyG7kYaZcM3VOskcPUrdCQd/nx8obc=", 28 + "rev": "46db2e09e1d3f113a13c0d7b81e2f221c63b8ce9", 29 + "revCount": 969196, 30 30 "type": "tarball", 31 - "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.964859%2Brev-b40629efe5d6ec48dd1efba650c797ddbd39ace0/019d03e9-2959-7276-adaa-d074e96422de/source.tar.gz" 31 + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.969196%2Brev-46db2e09e1d3f113a13c0d7b81e2f221c63b8ce9/019d279e-af65-79ce-92be-5dee7b1e36d4/source.tar.gz" 32 32 }, 33 33 "original": { 34 34 "type": "tarball", ··· 44 44 "rust-analyzer-src": { 45 45 "flake": false, 46 46 "locked": { 47 - "lastModified": 1774097238, 48 - "narHash": "sha256-hcujm/qEX4RUybdBCrQKdQNqTRYDItmnbjJRP5ky5vc=", 47 + "lastModified": 1774454876, 48 + "narHash": "sha256-bwkM8HseUs/22x+hy6FWvJMP6q/2CKBrm4sYxz9rMY8=", 49 49 "owner": "rust-lang", 50 50 "repo": "rust-analyzer", 51 - "rev": "76de1de27c0ca1329bc41324edab22c82d69e779", 51 + "rev": "9253d39eab8b9c9da3c1412fc94764e01d55a02b", 52 52 "type": "github" 53 53 }, 54 54 "original": {