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.
This commit is contained in:
Richard Newman 2017-03-06 20:14:50 -08:00
parent e898df8842
commit 7bcf311db9
4 changed files with 21 additions and 21 deletions

View file

@ -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));

View file

@ -331,25 +331,6 @@ pub fn ensure_current_version(conn: &mut rusqlite::Connection) -> Result<DB> {
}
}
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<TypedValue>;
fn to_sql_value_pair<'a>(&'a self) -> (ToSqlOutput<'a>, i32);

View file

@ -41,7 +41,6 @@ mod values;
mod tx;
pub use db::{
SQLValueType,
TypedSQLValue,
new_connection,
};

View file

@ -27,11 +27,11 @@ use rusqlite::{
};
use mentat_core::{
SQLValueType,
TypedValue,
};
use mentat_db::{
SQLValueType,
TypedSQLValue,
};