diff --git a/query-algebrizer/src/cc.rs b/query-algebrizer/src/cc.rs index ea146b0e..1dc8863f 100644 --- a/query-algebrizer/src/cc.rs +++ b/query-algebrizer/src/cc.rs @@ -45,84 +45,13 @@ use self::mentat_query::{ Variable, }; -/// This enum models the fixed set of default tables we have -- two -/// tables and two views. -#[derive(PartialEq, Eq, Clone, Copy, Debug)] -pub enum DatomsTable { - Datoms, // The non-fulltext datoms table. - FulltextValues, // The virtual table mapping IDs to strings. - FulltextDatoms, // The fulltext-datoms view. - AllDatoms, // Fulltext and non-fulltext datoms. -} - -impl DatomsTable { - pub fn name(&self) -> &'static str { - match *self { - DatomsTable::Datoms => "datoms", - DatomsTable::FulltextValues => "fulltext_values", - DatomsTable::FulltextDatoms => "fulltext_datoms", - DatomsTable::AllDatoms => "all_datoms", - } - } -} - -/// One of the named columns of our tables. -#[derive(PartialEq, Eq, Clone, Debug)] -pub enum DatomsColumn { - Entity, - Attribute, - Value, - Tx, - ValueTypeTag, -} - -impl DatomsColumn { - pub fn as_str(&self) -> &'static str { - use DatomsColumn::*; - match *self { - Entity => "e", - Attribute => "a", - Value => "v", - Tx => "tx", - ValueTypeTag => "value_type_tag", - } - } -} - - -/// A specific instance of a table within a query. E.g., "datoms123". -pub type TableAlias = String; - -/// The association between a table and its alias. E.g., AllDatoms, "all_datoms123". -#[derive(PartialEq, Eq, Clone)] -pub struct SourceAlias(pub DatomsTable, pub TableAlias); - -impl Debug for SourceAlias { - fn fmt(&self, f: &mut Formatter) -> Result { - write!(f, "SourceAlias({:?}, {})", self.0, self.1) - } -} - -/// A particular column of a particular aliased table. E.g., "datoms123", Attribute. -#[derive(PartialEq, Eq, Clone)] -pub struct QualifiedAlias(pub TableAlias, pub DatomsColumn); - -impl Debug for QualifiedAlias { - fn fmt(&self, f: &mut Formatter) -> Result { - write!(f, "{}.{}", self.0, self.1.as_str()) - } -} - -impl QualifiedAlias { - fn for_type_tag(&self) -> QualifiedAlias { - QualifiedAlias(self.0.clone(), DatomsColumn::ValueTypeTag) - } - - #[inline] - fn is_value(&self) -> bool { - self.1 == DatomsColumn::Value - } -} +use types::{ + DatomsColumn, + DatomsTable, + QualifiedAlias, + SourceAlias, + TableAlias, +}; /// A thing that's capable of aliasing a table name for us. /// This exists so that we can obtain predictable names in tests. diff --git a/query-algebrizer/src/lib.rs b/query-algebrizer/src/lib.rs index f0189e64..653ea96a 100644 --- a/query-algebrizer/src/lib.rs +++ b/query-algebrizer/src/lib.rs @@ -11,6 +11,7 @@ extern crate mentat_core; extern crate mentat_query; +mod types; mod cc; use mentat_core::{ @@ -84,7 +85,7 @@ pub use cc::{ ConjoiningClauses, }; -pub use cc::{ +pub use types::{ DatomsColumn, DatomsTable, QualifiedAlias, diff --git a/query-algebrizer/src/types.rs b/query-algebrizer/src/types.rs new file mode 100644 index 00000000..8791f1cc --- /dev/null +++ b/query-algebrizer/src/types.rs @@ -0,0 +1,88 @@ +// Copyright 2016 Mozilla +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +use std::fmt::{ + Debug, + Formatter, + Result, +}; + +/// This enum models the fixed set of default tables we have -- two +/// tables and two views. +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +pub enum DatomsTable { + Datoms, // The non-fulltext datoms table. + FulltextValues, // The virtual table mapping IDs to strings. + FulltextDatoms, // The fulltext-datoms view. + AllDatoms, // Fulltext and non-fulltext datoms. +} + +impl DatomsTable { + pub fn name(&self) -> &'static str { + match *self { + DatomsTable::Datoms => "datoms", + DatomsTable::FulltextValues => "fulltext_values", + DatomsTable::FulltextDatoms => "fulltext_datoms", + DatomsTable::AllDatoms => "all_datoms", + } + } +} + +/// One of the named columns of our tables. +#[derive(PartialEq, Eq, Clone, Debug)] +pub enum DatomsColumn { + Entity, + Attribute, + Value, + Tx, + ValueTypeTag, +} + +impl DatomsColumn { + pub fn as_str(&self) -> &'static str { + use self::DatomsColumn::*; + match *self { + Entity => "e", + Attribute => "a", + Value => "v", + Tx => "tx", + ValueTypeTag => "value_type_tag", + } + } +} + +/// A specific instance of a table within a query. E.g., "datoms123". +pub type TableAlias = String; + +/// The association between a table and its alias. E.g., AllDatoms, "all_datoms123". +#[derive(PartialEq, Eq, Clone)] +pub struct SourceAlias(pub DatomsTable, pub TableAlias); + +impl Debug for SourceAlias { + fn fmt(&self, f: &mut Formatter) -> Result { + write!(f, "SourceAlias({:?}, {})", self.0, self.1) + } +} + +/// A particular column of a particular aliased table. E.g., "datoms123", Attribute. +#[derive(PartialEq, Eq, Clone)] +pub struct QualifiedAlias(pub TableAlias, pub DatomsColumn); + +impl Debug for QualifiedAlias { + fn fmt(&self, f: &mut Formatter) -> Result { + write!(f, "{}.{}", self.0, self.1.as_str()) + } +} + +impl QualifiedAlias { + pub fn for_type_tag(&self) -> QualifiedAlias { + QualifiedAlias(self.0.clone(), DatomsColumn::ValueTypeTag) + } +} \ No newline at end of file