aboutsummaryrefslogtreecommitdiffstats
path: root/log_db/src/record.rs
diff options
context:
space:
mode:
Diffstat (limited to 'log_db/src/record.rs')
-rw-r--r--log_db/src/record.rs64
1 files changed, 0 insertions, 64 deletions
diff --git a/log_db/src/record.rs b/log_db/src/record.rs
index c373897..8108fb5 100644
--- a/log_db/src/record.rs
+++ b/log_db/src/record.rs
@@ -48,70 +48,6 @@ impl Record {
pub fn at(&self, index: usize) -> &Value {
&self.values[index]
}
-
- pub fn validate<Field: Eq>(&self, schema: &[(Field, Type)]) -> DBResult<()> {
- // If there are more values than schema fields, it's an error.
- if self.values.len() > schema.len() {
- return Err(DBError::ValidationError(format!(
- "Record has more fields ({}) than expected by the schema ({})",
- self.values.len(),
- schema.len()
- )));
- }
-
- for (i, (_, typ)) in schema.iter().enumerate() {
- match self.values.get(i) {
- Some(value) => {
- if !Self::value_matches_type(value, typ) {
- return Err(DBError::ValidationError(format!(
- "Record field {} has incorrect type: {:?}, expected {:?}",
- i, value, typ.primitive
- )));
- }
- }
- // If the field is missing from the record...
- None => {
- // ...it's allowed only if the schema says the field is nullable.
- if !typ.nullable {
- return Err(DBError::ValidationError(format!(
- "Record is missing field expected by the schema ({:?}) at index {}",
- typ, i
- )));
- }
- }
- }
- }
-
- Ok(())
- }
-
- fn value_matches_type(value: &Value, typ: &Type) -> bool {
- match (value, typ) {
- (Value::Null, Type { nullable: true, .. }) => true,
- (
- Value::Int(_),
- Type {
- primitive: PrimitiveType::Int,
- ..
- },
- ) => true,
- (
- Value::String(_),
- Type {
- primitive: PrimitiveType::String,
- ..
- },
- ) => true,
- (
- Value::Bytes(_),
- Type {
- primitive: PrimitiveType::Bytes,
- ..
- },
- ) => true,
- _ => false,
- }
- }
}
#[cfg(test)]