From f0702c01ee097c327b1d37978794705c55451290 Mon Sep 17 00:00:00 2001 From: William Brown Date: Mon, 12 Nov 2018 16:51:45 +1300 Subject: [PATCH] Initial structures for schema --- src/lib.rs | 1 + src/schema.rs | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/schema.rs diff --git a/src/lib.rs b/src/lib.rs index 252dafd71..837d508f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,3 +28,4 @@ pub mod event; pub mod filter; pub mod proto; pub mod server; +pub mod schema; diff --git a/src/schema.rs b/src/schema.rs new file mode 100644 index 000000000..62311667c --- /dev/null +++ b/src/schema.rs @@ -0,0 +1,70 @@ +use std::collections::HashMap; + +// representations of schema that confines object types, classes +// and attributes. This ties in deeply with "Entry". +// This only defines the types, and how they are represented. For +// application and validation of the schema, see "Entry". +// +// In the future this will parse/read it's schema from the db +// but we have to bootstrap with some core types. + +pub enum IndexType { + EQUALITY, + PRESENCE, + SUBSTRING, +} + +pub enum SyntaxType { + UTF8STRING, +} + +pub struct SchemaAttribute { + name: String, + description: String, + system: bool, + multivalue: bool, + index: Vec, + syntax: SyntaxType, +} + +pub struct SchemaClass { + name: String, + descriptions: String, + systemmay: Vec, + may: Vec, + systemmust: Vec, + must: Vec, +} + +pub struct Schema { + // We contain sets of classes and attributes. + classes: HashMap, + attributes: HashMap, +} + +impl Schema { + pub fn new() -> Self { + // + // Bootstrap in definitions of our own schema types + Schema { + classes: HashMap::new(), + attributes: HashMap::new(), + } + } +} + + +#[cfg(test)] +mod tests { + use super::{Schema, SchemaClass, SchemaAttribute}; + use super::super::entry::Entry; + + #[test] + fn test_schema_attribute_simple() { + // Test basic functions of simple attributes + } + + #[test] + fn test_schema_simple() { + } +}