Pre: Move db/errors.rs into db_traits

This commit is contained in:
Grisha Kruglov 2018-08-08 10:37:59 -07:00 committed by Grisha Kruglov
parent d0214fad7d
commit cebb85a7fe
33 changed files with 100 additions and 42 deletions

View file

@ -55,6 +55,9 @@ path = "sql"
[dependencies.mentat_db] [dependencies.mentat_db]
path = "db" path = "db"
[dependencies.db_traits]
path = "db-traits"
[dependencies.mentat_query] [dependencies.mentat_query]
path = "query" path = "query"

22
db-traits/Cargo.toml Normal file
View file

@ -0,0 +1,22 @@
[package]
name = "db_traits"
version = "0.0.1"
workspace = ".."
[lib]
name = "db_traits"
path = "lib.rs"
[dependencies]
failure = "0.1.1"
failure_derive = "0.1.1"
[dependencies.edn]
path = "../edn"
[dependencies.core_traits]
path = "../core-traits"
[dependencies.rusqlite]
version = "0.13"
features = ["limits"]

20
db-traits/lib.rs Normal file
View file

@ -0,0 +1,20 @@
// Copyright 2018 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 failure;
#[macro_use]
extern crate failure_derive;
extern crate rusqlite;
extern crate edn;
extern crate core_traits;
pub mod errors;

View file

@ -10,7 +10,6 @@ syncable = ["serde", "serde_json", "serde_derive"]
[dependencies] [dependencies]
failure = "0.1.1" failure = "0.1.1"
failure_derive = "0.1.1"
indexmap = "1" indexmap = "1"
itertools = "0.7" itertools = "0.7"
lazy_static = "0.2" lazy_static = "0.2"
@ -35,6 +34,9 @@ path = "../core"
[dependencies.core_traits] [dependencies.core_traits]
path = "../core-traits" path = "../core-traits"
[dependencies.db_traits]
path = "../db-traits"
[dependencies.mentat_sql] [dependencies.mentat_sql]
path = "../sql" path = "../sql"

View file

@ -11,7 +11,7 @@
#![allow(dead_code)] #![allow(dead_code)]
use edn; use edn;
use errors::{ use db_traits::errors::{
DbErrorKind, DbErrorKind,
Result, Result,
}; };

View file

@ -110,7 +110,7 @@ use db::{
TypedSQLValue, TypedSQLValue,
}; };
use errors::{ use db_traits::errors::{
DbError, DbError,
DbErrorKind, DbErrorKind,
Result, Result,

View file

@ -59,10 +59,11 @@ use mentat_core::{
ValueRc, ValueRc,
}; };
use errors::{ use db_traits::errors::{
DbErrorKind, DbErrorKind,
Result, Result,
}; };
use metadata; use metadata;
use schema::{ use schema::{
SchemaBuilding, SchemaBuilding,
@ -1237,7 +1238,7 @@ mod tests {
use std::collections::{ use std::collections::{
BTreeMap, BTreeMap,
}; };
use errors; use db_traits::errors as errors;
use internal_types::{ use internal_types::{
Term, Term,
}; };

View file

@ -65,7 +65,7 @@ use db::*;
use db::{read_attribute_map,read_ident_map}; use db::{read_attribute_map,read_ident_map};
use edn; use edn;
use entids; use entids;
use errors::Result; use db_traits::errors::Result;
use core_traits::{ use core_traits::{
Entid, Entid,

View file

@ -41,8 +41,8 @@ use edn::entities::{
TxFunction, TxFunction,
}; };
use errors; use db_traits::errors as errors;
use errors::{ use db_traits::errors::{
DbErrorKind, DbErrorKind,
Result, Result,
}; };

View file

@ -9,7 +9,6 @@
// specific language governing permissions and limitations under the License. // specific language governing permissions and limitations under the License.
extern crate failure; extern crate failure;
#[macro_use] extern crate failure_derive;
extern crate indexmap; extern crate indexmap;
extern crate itertools; extern crate itertools;
#[macro_use] extern crate lazy_static; #[macro_use] extern crate lazy_static;
@ -25,6 +24,7 @@ extern crate time;
#[macro_use] extern crate edn; #[macro_use] extern crate edn;
#[macro_use] extern crate mentat_core; #[macro_use] extern crate mentat_core;
#[macro_use] extern crate db_traits;
extern crate core_traits; extern crate core_traits;
extern crate mentat_sql; extern crate mentat_sql;
@ -32,13 +32,10 @@ use std::iter::repeat;
use itertools::Itertools; use itertools::Itertools;
pub use errors::{ use db_traits::errors::{
DbError,
DbErrorKind, DbErrorKind,
Result, Result,
SchemaConstraintViolation,
}; };
#[macro_use] pub mod errors;
#[macro_use] pub mod debug; #[macro_use] pub mod debug;

View file

@ -34,7 +34,7 @@ use add_retract_alter_set::{
}; };
use edn::symbols; use edn::symbols;
use entids; use entids;
use errors::{ use db_traits::errors::{
DbErrorKind, DbErrorKind,
Result, Result,
}; };

View file

@ -12,7 +12,7 @@
use db::TypedSQLValue; use db::TypedSQLValue;
use edn; use edn;
use errors::{ use db_traits::errors::{
DbErrorKind, DbErrorKind,
Result, Result,
}; };

View file

@ -12,7 +12,7 @@ use std::ops::RangeFrom;
use rusqlite; use rusqlite;
use errors::{ use db_traits::errors::{
DbErrorKind, DbErrorKind,
Result, Result,
}; };

View file

@ -66,8 +66,8 @@ use edn::{
Keyword, Keyword,
}; };
use entids; use entids;
use errors; use db_traits::errors as errors;
use errors::{ use db_traits::errors::{
DbErrorKind, DbErrorKind,
Result, Result,
}; };

View file

@ -19,7 +19,7 @@ use core_traits::{
ValueType, ValueType,
}; };
use errors::{ use db_traits::errors::{
CardinalityConflict, CardinalityConflict,
}; };

View file

@ -39,7 +39,7 @@ use edn::entities::{
OpType, OpType,
}; };
use errors::{ use db_traits::errors::{
Result, Result,
}; };

View file

@ -45,7 +45,7 @@ use edn::entities::{
TempId, TempId,
}; };
use errors; use db_traits::errors as errors;
/// Represents one partition of the entid space. /// Represents one partition of the entid space.
#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] #[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]

View file

@ -21,7 +21,7 @@ use std::collections::{
use indexmap; use indexmap;
use petgraph::unionfind; use petgraph::unionfind;
use errors::{ use db_traits::errors::{
DbErrorKind, DbErrorKind,
Result, Result,
}; };

View file

@ -30,7 +30,7 @@ use edn::entities::{
OpType, OpType,
}; };
use errors::{ use db_traits::errors::{
Result, Result,
}; };

View file

@ -21,6 +21,9 @@ path = "../core"
[dependencies.mentat_db] [dependencies.mentat_db]
path = "../db" path = "../db"
[dependencies.db_traits]
path = "../db-traits"
[dependencies.mentat_sql] [dependencies.mentat_sql]
path = "../sql" path = "../sql"

View file

@ -15,7 +15,7 @@ use rusqlite;
use mentat_core::{ use mentat_core::{
ValueTypeSet, ValueTypeSet,
}; };
use mentat_db; use db_traits::errors::DbError;
use mentat_query::{ use mentat_query::{
PlainSymbol, PlainSymbol,
}; };
@ -71,7 +71,7 @@ pub enum ProjectorError {
RusqliteError(String), RusqliteError(String),
#[fail(display = "{}", _0)] #[fail(display = "{}", _0)]
DbError(#[cause] mentat_db::DbError), DbError(#[cause] DbError),
#[fail(display = "{}", _0)] #[fail(display = "{}", _0)]
PullError(#[cause] mentat_query_pull::PullError), PullError(#[cause] mentat_query_pull::PullError),
@ -83,8 +83,8 @@ impl From<rusqlite::Error> for ProjectorError {
} }
} }
impl From<mentat_db::DbError> for ProjectorError { impl From<DbError> for ProjectorError {
fn from(error: mentat_db::DbError) -> ProjectorError { fn from(error: DbError) -> ProjectorError {
ProjectorError::DbError(error) ProjectorError::DbError(error)
} }
} }

View file

@ -16,6 +16,7 @@ extern crate indexmap;
extern crate rusqlite; extern crate rusqlite;
extern crate mentat_core; extern crate mentat_core;
extern crate db_traits;
extern crate core_traits; extern crate core_traits;
extern crate mentat_db; // For value conversion. extern crate mentat_db; // For value conversion.
extern crate mentat_query; extern crate mentat_query;

View file

@ -20,6 +20,9 @@ path = "../core-traits"
[dependencies.mentat_db] [dependencies.mentat_db]
path = "../db" path = "../db"
[dependencies.db_traits]
path = "../db-traits"
[dependencies.mentat_query] [dependencies.mentat_query]
path = "../query" path = "../query"

View file

@ -10,7 +10,7 @@
use std; // To refer to std::result::Result. use std; // To refer to std::result::Result.
use mentat_db::{ use db_traits::errors::{
DbError, DbError,
}; };

View file

@ -67,6 +67,7 @@ extern crate rusqlite;
extern crate mentat_core; extern crate mentat_core;
extern crate core_traits; extern crate core_traits;
extern crate mentat_db; extern crate mentat_db;
extern crate db_traits;
extern crate mentat_query; extern crate mentat_query;
extern crate mentat_query_algebrizer; extern crate mentat_query_algebrizer;
extern crate mentat_query_sql; extern crate mentat_query_sql;

View file

@ -562,7 +562,7 @@ impl<'a, 'o> TransactWatcher for InProgressTransactWatcher<'a, 'o> {
self.observer_watcher.datom(op.clone(), e.clone(), a.clone(), v); self.observer_watcher.datom(op.clone(), e.clone(), a.clone(), v);
} }
fn done(&mut self, t: &Entid, schema: &Schema) -> ::mentat_db::errors::Result<()> { fn done(&mut self, t: &Entid, schema: &Schema) -> ::db_traits::errors::Result<()> {
self.cache_watcher.done(t, schema)?; self.cache_watcher.done(t, schema)?;
self.observer_watcher.done(t, schema)?; self.observer_watcher.done(t, schema)?;
self.tx_id = Some(t.clone()); self.tx_id = Some(t.clone());
@ -895,7 +895,7 @@ mod tests {
match conn.transact(&mut sqlite, t.as_str()) { match conn.transact(&mut sqlite, t.as_str()) {
Err(MentatError::DbError(e)) => { Err(MentatError::DbError(e)) => {
assert_eq!(e.kind(), ::mentat_db::DbErrorKind::UnrecognizedEntid(next + 1)); assert_eq!(e.kind(), ::db_traits::errors::DbErrorKind::UnrecognizedEntid(next + 1));
}, },
x => panic!("expected db error, got {:?}", x), x => panic!("expected db error, got {:?}", x),
} }
@ -923,7 +923,7 @@ mod tests {
match conn.transact(&mut sqlite, t.as_str()) { match conn.transact(&mut sqlite, t.as_str()) {
Err(MentatError::DbError(e)) => { Err(MentatError::DbError(e)) => {
// All this, despite this being the ID we were about to allocate! // All this, despite this being the ID we were about to allocate!
assert_eq!(e.kind(), ::mentat_db::DbErrorKind::UnrecognizedEntid(next)); assert_eq!(e.kind(), ::db_traits::errors::DbErrorKind::UnrecognizedEntid(next));
}, },
x => panic!("expected db error, got {:?}", x), x => panic!("expected db error, got {:?}", x),
} }
@ -1107,7 +1107,7 @@ mod tests {
match report.expect_err("expected transact error") { match report.expect_err("expected transact error") {
MentatError::DbError(e) => { MentatError::DbError(e) => {
match e.kind() { match e.kind() {
::mentat_db::DbErrorKind::SchemaConstraintViolation(_) => {}, ::db_traits::errors::DbErrorKind::SchemaConstraintViolation(_) => {},
_ => panic!("expected SchemaConstraintViolation"), _ => panic!("expected SchemaConstraintViolation"),
} }
}, },

View file

@ -282,6 +282,7 @@ impl<'a, 'c> EntityBuilder<InProgressBuilder<'a, 'c>> {
#[cfg(test)] #[cfg(test)]
mod testing { mod testing {
extern crate mentat_db; extern crate mentat_db;
extern crate db_traits;
use ::{ use ::{
Conn, Conn,
@ -326,7 +327,7 @@ mod testing {
// This should fail: unrecognized entid. // This should fail: unrecognized entid.
match in_progress.transact_entities(terms).expect_err("expected transact to fail") { match in_progress.transact_entities(terms).expect_err("expected transact to fail") {
MentatError::DbError(e) => { MentatError::DbError(e) => {
assert_eq!(e.kind(), mentat_db::DbErrorKind::UnrecognizedEntid(999)); assert_eq!(e.kind(), db_traits::errors::DbErrorKind::UnrecognizedEntid(999));
}, },
_ => panic!("Should have rejected the entid."), _ => panic!("Should have rejected the entid."),
} }

View file

@ -26,7 +26,7 @@ use mentat_core::{
Attribute, Attribute,
}; };
use mentat_db; use db_traits::errors::DbError;
use mentat_query; use mentat_query;
use mentat_query_algebrizer; use mentat_query_algebrizer;
use mentat_query_projector; use mentat_query_projector;
@ -98,7 +98,7 @@ pub enum MentatError {
EdnParseError(#[cause] edn::ParseError), EdnParseError(#[cause] edn::ParseError),
#[fail(display = "{}", _0)] #[fail(display = "{}", _0)]
DbError(#[cause] mentat_db::DbError), DbError(#[cause] DbError),
#[fail(display = "{}", _0)] #[fail(display = "{}", _0)]
AlgebrizerError(#[cause] mentat_query_algebrizer::AlgebrizerError), AlgebrizerError(#[cause] mentat_query_algebrizer::AlgebrizerError),
@ -135,8 +135,8 @@ impl From<edn::ParseError> for MentatError {
} }
} }
impl From<mentat_db::DbError> for MentatError { impl From<DbError> for MentatError {
fn from(error: mentat_db::DbError) -> MentatError { fn from(error: DbError) -> MentatError {
MentatError::DbError(error) MentatError::DbError(error)
} }
} }

View file

@ -25,6 +25,7 @@ pub extern crate edn;
extern crate mentat_core; extern crate mentat_core;
extern crate core_traits; extern crate core_traits;
extern crate mentat_db; extern crate mentat_db;
extern crate db_traits;
extern crate mentat_query; extern crate mentat_query;
extern crate mentat_query_algebrizer; extern crate mentat_query_algebrizer;
extern crate mentat_query_projector; extern crate mentat_query_projector;
@ -138,7 +139,6 @@ pub use edn::{
ToMicros, ToMicros,
ToMillis, ToMillis,
}; };
pub use mentat_db::DbError;
pub use mentat_query_algebrizer::AlgebrizerError; pub use mentat_query_algebrizer::AlgebrizerError;
pub use mentat_query_projector::{ pub use mentat_query_projector::{
BindingTuple, BindingTuple,

View file

@ -30,6 +30,9 @@ path = "../core-traits"
[dependencies.mentat_db] [dependencies.mentat_db]
path = "../db" path = "../db"
[dependencies.db_traits]
path = "../db-traits"
[dependencies.rusqlite] [dependencies.rusqlite]
version = "0.13" version = "0.13"
features = ["limits"] features = ["limits"]

View file

@ -14,7 +14,7 @@ use uuid;
use hyper; use hyper;
use serde_json; use serde_json;
use mentat_db; use db_traits::errors::DbError;
#[macro_export] #[macro_export]
macro_rules! bail { macro_rules! bail {
@ -46,7 +46,7 @@ pub enum TolstoyError {
NotYetImplemented(String), NotYetImplemented(String),
#[fail(display = "{}", _0)] #[fail(display = "{}", _0)]
DbError(#[cause] mentat_db::DbError), DbError(#[cause] DbError),
#[fail(display = "{}", _0)] #[fail(display = "{}", _0)]
SerializationError(#[cause] serde_json::Error), SerializationError(#[cause] serde_json::Error),
@ -69,8 +69,8 @@ pub enum TolstoyError {
UriError(#[cause] hyper::error::UriError), UriError(#[cause] hyper::error::UriError),
} }
impl From<mentat_db::DbError> for TolstoyError { impl From<DbError> for TolstoyError {
fn from(error: mentat_db::DbError) -> TolstoyError { fn from(error: DbError) -> TolstoyError {
TolstoyError::DbError(error) TolstoyError::DbError(error)
} }
} }

View file

@ -34,6 +34,7 @@ extern crate serde_json;
#[cfg_attr(test, macro_use)] extern crate mentat_db; #[cfg_attr(test, macro_use)] extern crate mentat_db;
extern crate mentat_core; extern crate mentat_core;
extern crate db_traits;
extern crate core_traits; extern crate core_traits;
extern crate rusqlite; extern crate rusqlite;
extern crate uuid; extern crate uuid;