-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
161 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use std::rc::Rc; | ||
|
||
use crate::datom::*; | ||
use crate::schema::attribute::*; | ||
use crate::schema::*; | ||
|
||
pub struct AttributeBuilder { | ||
id: u64, | ||
version: u64, | ||
ident: Option<Rc<str>>, | ||
value_type: Option<ValueType>, | ||
cardinality: Option<Cardinality>, | ||
doc: Option<Rc<str>>, | ||
unique: bool, | ||
} | ||
|
||
impl AttributeBuilder { | ||
pub fn new(id: u64) -> Self { | ||
Self { | ||
id, | ||
version: 0, | ||
ident: None, | ||
value_type: None, | ||
cardinality: None, | ||
doc: None, | ||
unique: false, | ||
} | ||
} | ||
|
||
pub fn consume(&mut self, datom: Datom) { | ||
self.version = self.version.max(datom.tx); | ||
match datom { | ||
Datom { | ||
attribute: DB_ATTR_IDENT_ID, | ||
value: Value::Str(ident), | ||
.. | ||
} => self.ident = Some(ident), | ||
Datom { | ||
attribute: DB_ATTR_TYPE_ID, | ||
value: Value::U64(value_type), | ||
.. | ||
} => self.value_type = ValueType::try_from(value_type).ok(), | ||
Datom { | ||
attribute: DB_ATTR_CARDINALITY_ID, | ||
value: Value::U64(cardinality), | ||
.. | ||
} => self.cardinality = Cardinality::try_from(cardinality).ok(), | ||
Datom { | ||
attribute: DB_ATTR_DOC_ID, | ||
value: Value::Str(doc), | ||
.. | ||
} => self.doc = Some(doc), | ||
Datom { | ||
attribute: DB_ATTR_UNIQUE_ID, | ||
value: Value::U64(1), | ||
.. | ||
} => self.unique = true, | ||
_ => (), | ||
} | ||
} | ||
|
||
pub fn build(self) -> Option<Attribute> { | ||
let ident = self.ident?; | ||
let value_type = self.value_type?; | ||
let cardinality = self.cardinality?; | ||
Some(Attribute { | ||
id: self.id, | ||
version: self.version, | ||
definition: AttributeDefinition { | ||
ident, | ||
value_type, | ||
cardinality, | ||
doc: self.doc, | ||
unique: self.unique, | ||
}, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod attribute_resolver; | ||
pub mod attribute_builder; | ||
pub mod disk; | ||
pub mod memory; | ||
pub mod restricts; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters