This commit is contained in:
kristof 2025-04-04 11:45:02 +02:00
parent bcfa874c2b
commit 04233e6f1a
11 changed files with 40 additions and 10 deletions

View File

@ -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

View File

@ -1,5 +0,0 @@
```bash
cargo test zaz::tests -- --test-threads=1
```

View File

@ -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"
}
}

View File

@ -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;

View File

@ -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};

View File

@ -0,0 +1,4 @@
segment_size: 524288
use_compression: false
version: 0.34
v

Binary file not shown.

View File

@ -0,0 +1,4 @@
segment_size: 524288
use_compression: false
version: 0.34
v

Binary file not shown.

View File

@ -0,0 +1,4 @@
segment_size: 524288
use_compression: false
version: 0.34
v

Binary file not shown.