From 04233e6f1ad3f3d065166892864424a3a6b126d0 Mon Sep 17 00:00:00 2001 From: kristof Date: Fri, 4 Apr 2025 11:45:02 +0200 Subject: [PATCH] ... --- herodb/README.md | 8 ++++++++ herodb/readme.md | 5 ----- herodb/src/models/biz/currency.rs | 17 ++++++++++++++++- herodb/src/models/biz/product.rs | 4 ++-- herodb/src/models/biz/sale.rs | 4 ++-- herodb/tmp/dbexample2/currency/conf | 4 ++++ herodb/tmp/dbexample2/currency/db | Bin 0 -> 138 bytes herodb/tmp/dbexample2/product/conf | 4 ++++ herodb/tmp/dbexample2/product/db | Bin 0 -> 511 bytes herodb/tmp/dbexample2/sale/conf | 4 ++++ herodb/tmp/dbexample2/sale/db | Bin 0 -> 426 bytes 11 files changed, 40 insertions(+), 10 deletions(-) delete mode 100644 herodb/readme.md create mode 100644 herodb/tmp/dbexample2/currency/conf create mode 100644 herodb/tmp/dbexample2/currency/db create mode 100644 herodb/tmp/dbexample2/product/conf create mode 100644 herodb/tmp/dbexample2/product/db create mode 100644 herodb/tmp/dbexample2/sale/conf create mode 100644 herodb/tmp/dbexample2/sale/db diff --git a/herodb/README.md b/herodb/README.md index 4ac2b11..edbc14c 100644 --- a/herodb/README.md +++ b/herodb/README.md @@ -2,6 +2,14 @@ A database library built on top of sled with model support. + + +## example + +```bash +cargo run --bin dbexample2 +``` + ## Features - Type-safe database operations diff --git a/herodb/readme.md b/herodb/readme.md deleted file mode 100644 index cc7c647..0000000 --- a/herodb/readme.md +++ /dev/null @@ -1,5 +0,0 @@ - - -```bash -cargo test zaz::tests -- --test-threads=1 -``` \ No newline at end of file diff --git a/herodb/src/models/biz/currency.rs b/herodb/src/models/biz/currency.rs index cdc7a01..28464a0 100644 --- a/herodb/src/models/biz/currency.rs +++ b/herodb/src/models/biz/currency.rs @@ -1,6 +1,6 @@ use chrono::{DateTime, Utc, Duration}; use serde::{Deserialize, Serialize}; -use crate::core::{SledModel, Storable}; // Import Sled traits from new location +use crate::db::base::{SledModel, Storable}; // Import Sled traits from db module /// Currency represents a monetary value with amount and currency code #[derive(Debug, Clone, Serialize, Deserialize)] @@ -54,3 +54,18 @@ impl CurrencyBuilder { }) } } + +// Implement Storable trait (provides default dump/load) +impl Storable for Currency {} + +// Implement SledModel trait +impl SledModel for Currency { + fn get_id(&self) -> String { + // Use the currency code as the ID + self.currency_code.clone() + } + + fn db_prefix() -> &'static str { + "currency" + } +} diff --git a/herodb/src/models/biz/product.rs b/herodb/src/models/biz/product.rs index b6ca886..678f601 100644 --- a/herodb/src/models/biz/product.rs +++ b/herodb/src/models/biz/product.rs @@ -1,6 +1,6 @@ use chrono::{DateTime, Utc, Duration}; use serde::{Deserialize, Serialize}; -use crate::core::{SledModel, Storable}; // Import Sled traits from new location +use crate::db::base::{SledModel, Storable}; // Import Sled traits from db module /// ProductType represents the type of a product @@ -355,4 +355,4 @@ impl SledModel for Product { } // Import Currency from the currency module -use super::Currency; +use crate::models::biz::Currency; diff --git a/herodb/src/models/biz/sale.rs b/herodb/src/models/biz/sale.rs index 9e49b11..bcfede1 100644 --- a/herodb/src/models/biz/sale.rs +++ b/herodb/src/models/biz/sale.rs @@ -1,5 +1,5 @@ -use super::product::Currency; // Use super:: for sibling module -use crate::core::{SledModel, Storable}; // Import Sled traits from new location +use crate::models::biz::Currency; // Use crate:: for importing from the module +use crate::db::base::{SledModel, Storable}; // Import Sled traits from db module // use super::db::Model; // Removed old Model trait import use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; diff --git a/herodb/tmp/dbexample2/currency/conf b/herodb/tmp/dbexample2/currency/conf new file mode 100644 index 0000000..4154d7c --- /dev/null +++ b/herodb/tmp/dbexample2/currency/conf @@ -0,0 +1,4 @@ +segment_size: 524288 +use_compression: false +version: 0.34 +vQÁ \ No newline at end of file diff --git a/herodb/tmp/dbexample2/currency/db b/herodb/tmp/dbexample2/currency/db new file mode 100644 index 0000000000000000000000000000000000000000..d5807330460e68a71f2e8bf53ebc9b4dff42a52a GIT binary patch literal 138 zcmeyr>p1^^2&iX(fCl^e3%}Wb?7~IIDp(mA7#UtGHZSDhU|@nOVECw1oX^3OB8!Eg3c|k{=otO{+TLf literal 0 HcmV?d00001 diff --git a/herodb/tmp/dbexample2/product/conf b/herodb/tmp/dbexample2/product/conf new file mode 100644 index 0000000..4154d7c --- /dev/null +++ b/herodb/tmp/dbexample2/product/conf @@ -0,0 +1,4 @@ +segment_size: 524288 +use_compression: false +version: 0.34 +vQÁ \ No newline at end of file diff --git a/herodb/tmp/dbexample2/product/db b/herodb/tmp/dbexample2/product/db new file mode 100644 index 0000000000000000000000000000000000000000..3e682e339f62f78818b879a0dac005b289195f14 GIT binary patch literal 511 zcmeyr>p1^^2&iX(fCl^e3%}Wb?7~IIDp(mA7#UtGHZSDhU|@nOVECw1oX^34}UC zDG%mwcYk48S=AbTbJv7*1sA&S zwA(%D-G0wWgFjUJ!=d%JMbxrhnJ+X@)bivk$rEhyO$oO};$~oCgvW&u06fyxaR2}S literal 0 HcmV?d00001 diff --git a/herodb/tmp/dbexample2/sale/conf b/herodb/tmp/dbexample2/sale/conf new file mode 100644 index 0000000..4154d7c --- /dev/null +++ b/herodb/tmp/dbexample2/sale/conf @@ -0,0 +1,4 @@ +segment_size: 524288 +use_compression: false +version: 0.34 +vQÁ \ No newline at end of file diff --git a/herodb/tmp/dbexample2/sale/db b/herodb/tmp/dbexample2/sale/db new file mode 100644 index 0000000000000000000000000000000000000000..a2c7114a61354c63734a6e8ece51aa0e99a155fc GIT binary patch literal 426 zcmeyr>p1^^2&iX(fCl^e3%}Wb?7~IIDp(mA7#UtGHZSDhU|@nOVECw1oX^3&o31CMPz5B_^lo`lf^ebHSF>>d32?#X}iXO1Cx)M&5`iUk63qimgq%4CMJdr zo=gXH@_(-mxML=h&YhUq`{dWZHwMnHzVG~hnB`jNeKF07Q)j-5h&qS#_!Zh7{t)6_ z^e{anIB@RHNe6zgIW#a>j~GiqOn(NXf=4E+CSM1HwT4kKhb=-_6d}i~<+LQ-! gI{)(ScfYRs7{h(FvXIyBlzK(*p9HU%RWB`y0dyC(QUCw| literal 0 HcmV?d00001