Rename or delete things so that there is only one type named Entid (#768)

* Delete the (apparently unused) EntId

* Rename edn's Entid to EntidOrIdent to avoid confusion with the Entid that's actually an i64

* Fix travis beta bustage (This is actually unrelated to entids, but is a trivial fix nonetheless)
This commit is contained in:
Thom 2018-06-26 16:34:18 -07:00 committed by GitHub
parent f335253d4c
commit 72a9b302f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 70 deletions

View file

@ -32,7 +32,7 @@ use mentat_core::{
ValueType,
};
use edn::entities::{
Entid,
EntidOrIdent,
};
use schema::{
SchemaBuilding,
@ -43,8 +43,8 @@ use types::Schema;
#[derive(Clone,Debug,Eq,Hash,Ord,PartialOrd,PartialEq)]
pub(crate) struct Datom {
// TODO: generalize this.
e: Entid,
a: Entid,
e: EntidOrIdent,
a: EntidOrIdent,
v: edn::Value,
tx: i64,
added: Option<bool>,
@ -70,10 +70,10 @@ pub(crate) struct FulltextValues(pub Vec<(i64, String)>);
impl Datom {
pub(crate) fn into_edn(&self) -> edn::Value {
let f = |entid: &Entid| -> edn::Value {
let f = |entid: &EntidOrIdent| -> edn::Value {
match *entid {
Entid::Entid(ref y) => edn::Value::Integer(y.clone()),
Entid::Ident(ref y) => edn::Value::Keyword(y.clone()),
EntidOrIdent::Entid(ref y) => edn::Value::Integer(y.clone()),
EntidOrIdent::Ident(ref y) => edn::Value::Keyword(y.clone()),
}
};
@ -121,8 +121,8 @@ impl ToIdent for TypedValue {
}
/// Convert a numeric entid to an ident `Entid` if possible, otherwise a numeric `Entid`.
fn to_entid(schema: &Schema, entid: i64) -> Entid {
schema.get_ident(entid).map_or(Entid::Entid(entid), |ident| Entid::Ident(ident.clone()))
fn to_entid(schema: &Schema, entid: i64) -> EntidOrIdent {
schema.get_ident(entid).map_or(EntidOrIdent::Entid(entid), |ident| EntidOrIdent::Ident(ident.clone()))
}
/// Return the set of datoms in the store, ordered by (e, a, v, tx), but not including any datoms of
@ -160,7 +160,7 @@ pub(crate) fn datoms_after<S: Borrow<Schema>>(conn: &rusqlite::Connection, schem
let tx: i64 = row.get_checked(4)?;
Ok(Some(Datom {
e: Entid::Entid(e),
e: EntidOrIdent::Entid(e),
a: to_entid(borrowed_schema, a),
v: value,
tx: tx,
@ -197,7 +197,7 @@ pub(crate) fn transactions_after<S: Borrow<Schema>>(conn: &rusqlite::Connection,
let added: bool = row.get_checked(5)?;
Ok(Datom {
e: Entid::Entid(e),
e: EntidOrIdent::Entid(e),
a: to_entid(borrowed_schema, a),
v: value,
tx: tx,

View file

@ -63,10 +63,10 @@ impl TransactableValue for ValueAndSpan {
fn into_entity_place(self) -> Result<EntityPlace<Self>> {
use self::SpannedValue::*;
match self.inner {
Integer(v) => Ok(EntityPlace::Entid(entities::Entid::Entid(v))),
Integer(v) => Ok(EntityPlace::Entid(entities::EntidOrIdent::Entid(v))),
Keyword(v) => {
if v.is_namespaced() {
Ok(EntityPlace::Entid(entities::Entid::Ident(v)))
Ok(EntityPlace::Entid(entities::EntidOrIdent::Ident(v)))
} else {
// We only allow namespaced idents.
bail!(DbError::InputError(errors::InputError::BadEntityPlace))
@ -121,8 +121,8 @@ impl TransactableValue for TypedValue {
fn into_entity_place(self) -> Result<EntityPlace<Self>> {
match self {
TypedValue::Ref(x) => Ok(EntityPlace::Entid(entities::Entid::Entid(x))),
TypedValue::Keyword(x) => Ok(EntityPlace::Entid(entities::Entid::Ident((*x).clone()))),
TypedValue::Ref(x) => Ok(EntityPlace::Entid(entities::EntidOrIdent::Entid(x))),
TypedValue::Keyword(x) => Ok(EntityPlace::Entid(entities::EntidOrIdent::Ident((*x).clone()))),
TypedValue::String(x) => Ok(EntityPlace::TempId(TempId::External((*x).clone()))),
TypedValue::Boolean(_) |
TypedValue::Long(_) |

View file

@ -168,7 +168,7 @@ pub struct Tx<'conn, 'a, W> where W: TransactWatcher {
/// something suitable for the entity position rather than something suitable for a value position.
pub fn remove_db_id<V: TransactableValue>(map: &mut entmod::MapNotation<V>) -> Result<Option<entmod::EntityPlace<V>>> {
// TODO: extract lazy defined constant.
let db_id_key = entmod::Entid::Ident(Keyword::namespaced("db", "id"));
let db_id_key = entmod::EntidOrIdent::Ident(Keyword::namespaced("db", "id"));
let db_id: Option<entmod::EntityPlace<V>> = if let Some(id) = map.remove(&db_id_key) {
match id {
@ -291,8 +291,8 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
fn intern_lookup_ref<W: TransactableValue>(&mut self, lookup_ref: &entmod::LookupRef<W>) -> Result<LookupRef> {
let lr_a: i64 = match lookup_ref.a {
AttributePlace::Entid(entmod::Entid::Entid(ref a)) => *a,
AttributePlace::Entid(entmod::Entid::Ident(ref a)) => self.schema.require_entid(&a)?.into(),
AttributePlace::Entid(entmod::EntidOrIdent::Entid(ref a)) => *a,
AttributePlace::Entid(entmod::EntidOrIdent::Ident(ref a)) => self.schema.require_entid(&a)?.into(),
};
let lr_attribute: &Attribute = self.schema.require_attribute_for_entid(lr_a)?;
@ -319,8 +319,8 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
match x {
entmod::EntityPlace::Entid(e) => {
let e = match e {
entmod::Entid::Entid(ref e) => self.ensure_entid_exists(*e)?,
entmod::Entid::Ident(ref e) => self.ensure_ident_exists(&e)?,
entmod::EntidOrIdent::Entid(ref e) => self.ensure_entid_exists(*e)?,
entmod::EntidOrIdent::Ident(ref e) => self.ensure_ident_exists(&e)?,
};
Ok(Either::Left(e))
},
@ -342,10 +342,10 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
}
}
fn entity_a_into_term_a(&mut self, x: entmod::Entid) -> Result<Entid> {
fn entity_a_into_term_a(&mut self, x: entmod::EntidOrIdent) -> Result<Entid> {
let a = match x {
entmod::Entid::Entid(ref a) => *a,
entmod::Entid::Ident(ref a) => self.schema.require_entid(&a)?.into(),
entmod::EntidOrIdent::Entid(ref a) => *a,
entmod::EntidOrIdent::Ident(ref a) => self.schema.require_entid(&a)?.into(),
};
Ok(a)
}
@ -354,7 +354,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
self.entity_e_into_term_e(x).map(|r| r.map_left(|ke| TypedValue::Ref(ke.0)))
}
fn entity_v_into_term_e<W: TransactableValue>(&mut self, x: entmod::ValuePlace<W>, backward_a: &entmod::Entid) -> Result<KnownEntidOr<LookupRefOrTempId>> {
fn entity_v_into_term_e<W: TransactableValue>(&mut self, x: entmod::ValuePlace<W>, backward_a: &entmod::EntidOrIdent) -> Result<KnownEntidOr<LookupRefOrTempId>> {
match backward_a.unreversed() {
None => {
bail!(DbError::NotYetImplemented(format!("Cannot explode map notation value in :attr/_reversed notation for forward attribute")));
@ -510,7 +510,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
deque.push_front(Entity::AddOrRetract {
op: op.clone(),
e: e.clone(),
a: AttributePlace::Entid(entmod::Entid::Entid(a)),
a: AttributePlace::Entid(entmod::EntidOrIdent::Entid(a)),
v: vv,
});
}
@ -573,7 +573,7 @@ impl<'conn, 'a, W> Tx<'conn, 'a, W> where W: TransactWatcher {
deque.push_front(Entity::AddOrRetract {
op: OpType::Add,
e: db_id.clone(),
a: AttributePlace::Entid(entmod::Entid::Entid(inner_a)),
a: AttributePlace::Entid(entmod::EntidOrIdent::Entid(inner_a)),
v: inner_v,
});
}

View file

@ -238,18 +238,18 @@ raw_forward_namespaced_keyword -> Keyword
raw_backward_namespaced_keyword -> Keyword
= v:raw_namespaced_keyword {? if v.is_backward() { Ok(v) } else { Err("expected namespaced :backward/_keyword") } }
entid -> Entid
= v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { Entid::Entid(v) }
/ v:raw_namespaced_keyword { Entid::Ident(v) }
entid -> EntidOrIdent
= v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { EntidOrIdent::Entid(v) }
/ v:raw_namespaced_keyword { EntidOrIdent::Ident(v) }
/ #expected("entid")
forward_entid -> Entid
= v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { Entid::Entid(v) }
/ v:raw_forward_namespaced_keyword { Entid::Ident(v) }
forward_entid -> EntidOrIdent
= v:( raw_basedinteger / raw_hexinteger / raw_octalinteger / raw_integer ) { EntidOrIdent::Entid(v) }
/ v:raw_forward_namespaced_keyword { EntidOrIdent::Ident(v) }
/ #expected("forward entid")
backward_entid -> Entid
= v:raw_backward_namespaced_keyword { Entid::Ident(v.to_reversed()) }
backward_entid -> EntidOrIdent
= v:raw_backward_namespaced_keyword { EntidOrIdent::Ident(v.to_reversed()) }
/ #expected("backward entid")
lookup_ref -> LookupRef<ValueAndSpan>
@ -265,7 +265,7 @@ entity_place -> EntityPlace<ValueAndSpan>
/ v:lookup_ref { EntityPlace::LookupRef(v) }
/ v:tx_function { EntityPlace::TxFunction(v) }
value_place_pair -> (Entid, ValuePlace<ValueAndSpan>)
value_place_pair -> (EntidOrIdent, ValuePlace<ValueAndSpan>)
= k:(entid) __ v:(value_place) { (k, v) }
map_notation -> MapNotation<ValueAndSpan>

View file

@ -45,16 +45,16 @@ impl fmt::Display for TempId {
}
#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum Entid {
pub enum EntidOrIdent {
Entid(i64),
Ident(Keyword),
}
impl Entid {
pub fn unreversed(&self) -> Option<Entid> {
impl EntidOrIdent {
pub fn unreversed(&self) -> Option<EntidOrIdent> {
match self {
&Entid::Entid(_) => None,
&Entid::Ident(ref a) => a.unreversed().map(Entid::Ident),
&EntidOrIdent::Entid(_) => None,
&EntidOrIdent::Ident(ref a) => a.unreversed().map(EntidOrIdent::Ident),
}
}
}
@ -84,13 +84,13 @@ pub struct TxFunction {
pub op: PlainSymbol,
}
pub type MapNotation<V> = BTreeMap<Entid, ValuePlace<V>>;
pub type MapNotation<V> = BTreeMap<EntidOrIdent, ValuePlace<V>>;
#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum ValuePlace<V> {
// We never know at parse-time whether an integer or ident is really an entid, but we will often
// know when building entities programmatically.
Entid(Entid),
Entid(EntidOrIdent),
// We never know at parse-time whether a string is really a tempid, but we will often know when
// building entities programmatically.
TempId(TempId),
@ -103,7 +103,7 @@ pub enum ValuePlace<V> {
#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum EntityPlace<V> {
Entid(Entid),
Entid(EntidOrIdent),
TempId(TempId),
LookupRef(LookupRef<V>),
TxFunction(TxFunction),
@ -111,7 +111,7 @@ pub enum EntityPlace<V> {
#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum AttributePlace {
Entid(Entid),
Entid(EntidOrIdent),
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]

View file

@ -71,7 +71,7 @@ impl Value {
Value::NamespacedSymbol(ref v) => pp.text(v.namespace()).append("/").append(v.name()),
Value::PlainSymbol(ref v) => pp.text(v.to_string()),
Value::Keyword(ref v) => pp.text(v.to_string()),
Value::Text(ref v) => pp.text("\"").append(v.as_ref()).append("\""),
Value::Text(ref v) => pp.text("\"").append(v.as_str()).append("\""),
Value::Uuid(ref u) => pp.text("#uuid \"").append(u.hyphenated().to_string()).append("\""),
Value::Instant(ref v) => pp.text("#inst \"").append(v.to_rfc3339_opts(SecondsFormat::AutoSi, true)).append("\""),
_ => pp.text(self.to_string())

View file

@ -1,25 +0,0 @@
// 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.
extern crate edn;
use edn::symbols::Keyword;
pub type EntId = u32; // TODO: u64? Not all DB values will be representable in a u32.
/// The ability to transform entity identifiers (entids) into keyword names (idents).
pub trait ToIdent {
fn ident(&self, entid: EntId) -> Option<Keyword>;
}
/// The ability to transform idents into the corresponding entid.
pub trait ToEntId {
fn entid(&self, ident: &Keyword) -> Option<EntId>;
}

View file

@ -106,7 +106,6 @@ macro_rules! kw {
pub mod errors;
pub mod conn;
pub mod entity_builder;
pub mod ident;
pub mod query;
pub mod query_builder;
pub mod store;