From 68d0e1782457f603d4341b0032c274234fa33675 Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Wed, 8 Aug 2018 13:19:08 -0700 Subject: [PATCH] Pre: Move sql/errors into sql_traits --- Cargo.toml | 3 +++ query-sql/Cargo.toml | 3 +++ query-sql/src/lib.rs | 8 ++++++-- sql-traits/Cargo.toml | 12 ++++++++++++ sql-traits/errors.rs | 20 ++++++++++++++++++++ sql-traits/lib.rs | 15 +++++++++++++++ sql/Cargo.toml | 4 +++- sql/src/lib.rs | 19 +++++++------------ src/errors.rs | 10 ++++++---- src/lib.rs | 3 ++- 10 files changed, 77 insertions(+), 20 deletions(-) create mode 100644 sql-traits/Cargo.toml create mode 100644 sql-traits/errors.rs create mode 100644 sql-traits/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 04689e16..7945aa2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,6 +79,9 @@ path = "query-pull-traits" [dependencies.mentat_query_sql] path = "query-sql" +[dependencies.sql_traits] +path = "sql-traits" + [dependencies.mentat_tolstoy] path = "tolstoy" optional = true diff --git a/query-sql/Cargo.toml b/query-sql/Cargo.toml index 98e4e15b..f44a5a0c 100644 --- a/query-sql/Cargo.toml +++ b/query-sql/Cargo.toml @@ -17,5 +17,8 @@ path = "../core" [dependencies.mentat_sql] path = "../sql" +[dependencies.sql_traits] +path = "../sql-traits" + [dependencies.mentat_query_algebrizer] path = "../query-algebrizer" diff --git a/query-sql/src/lib.rs b/query-sql/src/lib.rs index 7cd984b9..3aa9a0cf 100644 --- a/query-sql/src/lib.rs +++ b/query-sql/src/lib.rs @@ -10,6 +10,7 @@ #[macro_use] extern crate mentat_core; extern crate core_traits; +extern crate sql_traits; extern crate edn; extern crate mentat_query_algebrizer; extern crate mentat_sql; @@ -42,11 +43,14 @@ use mentat_query_algebrizer::{ VariableColumn, }; -use mentat_sql::{ +use sql_traits::errors::{ BuildQueryResult, + SQLError, +}; + +use mentat_sql::{ QueryBuilder, QueryFragment, - SQLError, SQLiteQueryBuilder, SQLQuery, }; diff --git a/sql-traits/Cargo.toml b/sql-traits/Cargo.toml new file mode 100644 index 00000000..211e998c --- /dev/null +++ b/sql-traits/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "sql_traits" +version = "0.0.1" +workspace = ".." + +[lib] +name = "sql_traits" +path = "lib.rs" + +[dependencies] +failure = "0.1.1" +failure_derive = "0.1.1" diff --git a/sql-traits/errors.rs b/sql-traits/errors.rs new file mode 100644 index 00000000..e57c674f --- /dev/null +++ b/sql-traits/errors.rs @@ -0,0 +1,20 @@ +// 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. + +#[derive(Debug, Fail)] +pub enum SQLError { + #[fail(display = "invalid parameter name: {}", _0)] + InvalidParameterName(String), + + #[fail(display = "parameter name could be generated: '{}'", _0)] + BindParamCouldBeGenerated(String) +} + +pub type BuildQueryResult = Result<(), SQLError>; diff --git a/sql-traits/lib.rs b/sql-traits/lib.rs new file mode 100644 index 00000000..34588993 --- /dev/null +++ b/sql-traits/lib.rs @@ -0,0 +1,15 @@ +// 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 failure; +#[macro_use] +extern crate failure_derive; + +pub mod errors; diff --git a/sql/Cargo.toml b/sql/Cargo.toml index 133e2335..d39f9149 100644 --- a/sql/Cargo.toml +++ b/sql/Cargo.toml @@ -5,7 +5,6 @@ workspace = ".." [dependencies] failure = "0.1.1" -failure_derive = "0.1.1" ordered-float = "0.5" [dependencies.rusqlite] @@ -17,3 +16,6 @@ path = "../core-traits" [dependencies.mentat_core] path = "../core" + +[dependencies.sql_traits] +path = "../sql-traits" diff --git a/sql/src/lib.rs b/sql/src/lib.rs index 3cf59340..35f31a44 100644 --- a/sql/src/lib.rs +++ b/sql/src/lib.rs @@ -7,13 +7,14 @@ // 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 ordered_float; extern crate rusqlite; extern crate core_traits; +extern crate sql_traits; extern crate mentat_core; use std::rc::Rc; @@ -26,6 +27,11 @@ use core_traits::{ TypedValue, }; +use sql_traits::errors::{ + BuildQueryResult, + SQLError, +}; + use mentat_core::{ ToMicros, ValueRc, @@ -33,17 +39,6 @@ use mentat_core::{ pub use rusqlite::types::Value; -#[derive(Debug, Fail)] -pub enum SQLError { - #[fail(display = "invalid parameter name: {}", _0)] - InvalidParameterName(String), - - #[fail(display = "parameter name could be generated: '{}'", _0)] - BindParamCouldBeGenerated(String) -} - -pub type BuildQueryResult = Result<(), SQLError>; - /// We want to accumulate values that will later be substituted into a SQL statement execution. /// This struct encapsulates the generated string and the _initial_ argument list. /// Additional user-supplied argument bindings, with their placeholders accumulated via diff --git a/src/errors.rs b/src/errors.rs index eb990d11..2350cceb 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -36,7 +36,9 @@ use query_projector_traits::errors::{ use query_pull_traits::errors::{ PullError, }; -use mentat_sql; +use sql_traits::errors::{ + SQLError, +}; #[cfg(feature = "syncable")] use mentat_tolstoy; @@ -115,7 +117,7 @@ pub enum MentatError { PullError(#[cause] PullError), #[fail(display = "{}", _0)] - SQLError(#[cause] mentat_sql::SQLError), + SQLError(#[cause] SQLError), #[cfg(feature = "syncable")] #[fail(display = "{}", _0)] @@ -164,8 +166,8 @@ impl From for MentatError { } } -impl From for MentatError { - fn from(error: mentat_sql::SQLError) -> MentatError { +impl From for MentatError { + fn from(error: SQLError) -> MentatError { MentatError::SQLError(error) } } diff --git a/src/lib.rs b/src/lib.rs index c4464d3b..cb0c14df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,7 @@ extern crate mentat_query_projector; extern crate query_projector_traits; extern crate mentat_query_pull; extern crate query_pull_traits; +extern crate sql_traits; extern crate mentat_sql; #[cfg(feature = "syncable")] @@ -148,7 +149,7 @@ pub use mentat_query_projector::{ BindingTuple, }; pub use query_pull_traits::errors::PullError; -pub use mentat_sql::SQLError; +pub use sql_traits::errors::SQLError; pub mod conn; pub mod entity_builder;