From bea37e2834a5265035b960277ff27e5f8d74d079 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 21 Feb 2025 14:16:24 +0200 Subject: Start working in new schema logic to core --- log_db/src/config.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'log_db/src/config.rs') diff --git a/log_db/src/config.rs b/log_db/src/config.rs index 5b3cf26..ec74164 100644 --- a/log_db/src/config.rs +++ b/log_db/src/config.rs @@ -6,23 +6,23 @@ pub struct Schema { pub secondary_keys: Vec, } -pub struct ConfigBuilder { +pub struct ConfigBuilder { data_dir: Option, segment_size: Option, write_durability: Option, read_consistency: Option, - fields: Option>, - primary_key: Option, - secondary_keys: Option>, + fields: Option>, + primary_key: Option, + secondary_keys: Option>, from_record: Option) -> T>, into_record: Option Vec>, _marker: PhantomData, } -impl ConfigBuilder { - pub fn new() -> ConfigBuilder { +impl ConfigBuilder { + pub fn new() -> ConfigBuilder { ConfigBuilder { data_dir: None, segment_size: None, @@ -71,18 +71,18 @@ impl ConfigBuilder { self } - pub fn fields(mut self, schema: Vec) -> Self { - self.fields = Some(schema); + pub fn fields(mut self, schema: Vec>) -> Self { + self.fields = Some(schema.into_iter().map(|s| s.into()).collect()); self } - pub fn primary_key(mut self, primary_key: F) -> Self { - self.primary_key = Some(primary_key); + pub fn primary_key(mut self, primary_key: impl Into) -> Self { + self.primary_key = Some(primary_key.into()); self } - pub fn secondary_keys(mut self, secondary_keys: Vec) -> Self { - self.secondary_keys = Some(secondary_keys); + pub fn secondary_keys(mut self, secondary_keys: Vec>) -> Self { + self.secondary_keys = Some(secondary_keys.into_iter().map(|s| s.into()).collect()); self } @@ -96,7 +96,7 @@ impl ConfigBuilder { self } - pub fn initialize(self) -> DBResult> { + pub fn initialize(self) -> DBResult> { let schema = self .fields .ok_or_else(|| DBError::ValidationError("Schema not set".to_string()))?; @@ -134,10 +134,10 @@ impl ConfigBuilder { } #[derive(Clone)] -pub struct Config { - pub schema: Vec, - pub primary_key: F, - pub secondary_keys: Vec, +pub struct Config { + pub schema: Vec, + pub primary_key: String, + pub secondary_keys: Vec, pub from_record: fn(Vec) -> T, pub into_record: fn(T) -> Vec, pub data_dir: String, -- cgit v1.3