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:
parent
e898df8842
commit
7bcf311db9
4 changed files with 21 additions and 21 deletions
|
@ -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));
|
||||
|
|
19
db/src/db.rs
19
db/src/db.rs
|
@ -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);
|
||||
|
|
|
@ -41,7 +41,6 @@ mod values;
|
|||
mod tx;
|
||||
|
||||
pub use db::{
|
||||
SQLValueType,
|
||||
TypedSQLValue,
|
||||
new_connection,
|
||||
};
|
||||
|
|
|
@ -27,11 +27,11 @@ use rusqlite::{
|
|||
};
|
||||
|
||||
use mentat_core::{
|
||||
SQLValueType,
|
||||
TypedValue,
|
||||
};
|
||||
|
||||
use mentat_db::{
|
||||
SQLValueType,
|
||||
TypedSQLValue,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue