From 7bcf311db9bf2347860c0631b3e903cbce4fc3c9 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Mon, 6 Mar 2017 20:14:50 -0800 Subject: [PATCH] Pre: move SQLValueType to core, because it's so central. Yes, this isn't tidy... but in order to be really tidy we'd need to split up db into parts that don't depend on a particular SQLite library. --- core/src/lib.rs | 20 ++++++++++++++++++++ db/src/db.rs | 19 ------------------- db/src/lib.rs | 1 - query-projector/src/lib.rs | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index 43f01bc2..36637680 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -76,6 +76,26 @@ impl TypedValue { } } +// Put this here rather than in `db` simply because it's widely needed. +pub trait SQLValueType { + fn value_type_tag(&self) -> i32; +} + +impl SQLValueType for ValueType { + fn value_type_tag(&self) -> i32 { + match *self { + ValueType::Ref => 0, + ValueType::Boolean => 1, + ValueType::Instant => 4, + // SQLite distinguishes integral from decimal types, allowing long and double to share a tag. + ValueType::Long => 5, + ValueType::Double => 5, + ValueType::String => 10, + ValueType::Keyword => 13, + } + } +} + #[test] fn test_typed_value() { assert!(TypedValue::Boolean(false).is_congruent_with(None)); diff --git a/db/src/db.rs b/db/src/db.rs index ee59276f..37d457ce 100644 --- a/db/src/db.rs +++ b/db/src/db.rs @@ -331,25 +331,6 @@ pub fn ensure_current_version(conn: &mut rusqlite::Connection) -> Result { } } -pub trait SQLValueType { - fn value_type_tag(&self) -> i32; -} - -impl SQLValueType for ValueType { - fn value_type_tag(&self) -> i32 { - match *self { - ValueType::Ref => 0, - ValueType::Boolean => 1, - ValueType::Instant => 4, - // SQLite distinguishes integral from decimal types, allowing long and double to share a tag. - ValueType::Long => 5, - ValueType::Double => 5, - ValueType::String => 10, - ValueType::Keyword => 13, - } - } -} - pub trait TypedSQLValue { fn from_sql_value_pair(value: rusqlite::types::Value, value_type_tag: i32) -> Result; fn to_sql_value_pair<'a>(&'a self) -> (ToSqlOutput<'a>, i32); diff --git a/db/src/lib.rs b/db/src/lib.rs index 287c1454..cde13ad9 100644 --- a/db/src/lib.rs +++ b/db/src/lib.rs @@ -41,7 +41,6 @@ mod values; mod tx; pub use db::{ - SQLValueType, TypedSQLValue, new_connection, }; diff --git a/query-projector/src/lib.rs b/query-projector/src/lib.rs index 364e5c2f..061bdff1 100644 --- a/query-projector/src/lib.rs +++ b/query-projector/src/lib.rs @@ -27,11 +27,11 @@ use rusqlite::{ }; use mentat_core::{ + SQLValueType, TypedValue, }; use mentat_db::{ - SQLValueType, TypedSQLValue, };