Part 3: handle instants in db.
This commit is contained in:
parent
abf625775f
commit
bc5ffdbc34
3 changed files with 8 additions and 1 deletions
|
@ -98,7 +98,7 @@ lazy_static! {
|
|||
;; TODO: support user-specified functions in the future.
|
||||
;; :db.install/function {:db/valueType :db.type/ref
|
||||
;; :db/cardinality :db.cardinality/many}
|
||||
:db/txInstant {:db/valueType :db.type/long
|
||||
:db/txInstant {:db/valueType :db.type/instant
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/index true}
|
||||
:db/valueType {:db/valueType :db.type/ref
|
||||
|
|
|
@ -40,10 +40,12 @@ use mentat_core::{
|
|||
Attribute,
|
||||
AttributeBitFlags,
|
||||
Entid,
|
||||
FromMicros,
|
||||
IdentMap,
|
||||
Schema,
|
||||
SchemaMap,
|
||||
TypedValue,
|
||||
ToMicros,
|
||||
ValueType,
|
||||
};
|
||||
use errors::{ErrorKind, Result, ResultExt};
|
||||
|
@ -352,6 +354,7 @@ impl TypedSQLValue for TypedValue {
|
|||
match (value_type_tag, value) {
|
||||
(0, rusqlite::types::Value::Integer(x)) => Ok(TypedValue::Ref(x)),
|
||||
(1, rusqlite::types::Value::Integer(x)) => Ok(TypedValue::Boolean(0 != x)),
|
||||
(4, rusqlite::types::Value::Integer(x)) => Ok(TypedValue::Instant(DateTime::<UTC>::from_micros(x))),
|
||||
// SQLite distinguishes integral from decimal types, allowing long and double to
|
||||
// share a tag.
|
||||
(5, rusqlite::types::Value::Integer(x)) => Ok(TypedValue::Long(x)),
|
||||
|
@ -383,6 +386,7 @@ impl TypedSQLValue for TypedValue {
|
|||
fn from_edn_value(value: &Value) -> Option<TypedValue> {
|
||||
match value {
|
||||
&Value::Boolean(x) => Some(TypedValue::Boolean(x)),
|
||||
&Value::Instant(x) => Some(TypedValue::Instant(x)),
|
||||
&Value::Integer(x) => Some(TypedValue::Long(x)),
|
||||
&Value::Uuid(x) => Some(TypedValue::Uuid(x)),
|
||||
&Value::Float(ref x) => Some(TypedValue::Double(x.clone())),
|
||||
|
@ -397,6 +401,7 @@ impl TypedSQLValue for TypedValue {
|
|||
match self {
|
||||
&TypedValue::Ref(x) => (rusqlite::types::Value::Integer(x).into(), 0),
|
||||
&TypedValue::Boolean(x) => (rusqlite::types::Value::Integer(if x { 1 } else { 0 }).into(), 1),
|
||||
&TypedValue::Instant(x) => (rusqlite::types::Value::Integer(x.to_micros()).into(), 4),
|
||||
// SQLite distinguishes integral from decimal types, allowing long and double to share a tag.
|
||||
&TypedValue::Long(x) => (rusqlite::types::Value::Integer(x).into(), 5),
|
||||
&TypedValue::Double(x) => (rusqlite::types::Value::Real(x.into_inner()).into(), 5),
|
||||
|
@ -411,6 +416,7 @@ impl TypedSQLValue for TypedValue {
|
|||
match self {
|
||||
&TypedValue::Ref(x) => (Value::Integer(x), ValueType::Ref),
|
||||
&TypedValue::Boolean(x) => (Value::Boolean(x), ValueType::Boolean),
|
||||
&TypedValue::Instant(x) => (Value::Instant(x), ValueType::Instant),
|
||||
&TypedValue::Long(x) => (Value::Integer(x), ValueType::Long),
|
||||
&TypedValue::Double(x) => (Value::Float(x), ValueType::Double),
|
||||
&TypedValue::String(ref x) => (Value::Text(x.as_ref().clone()), ValueType::String),
|
||||
|
|
|
@ -119,6 +119,7 @@ pub fn update_schema_map_from_entid_triples<U>(schema_map: &mut SchemaMap, asser
|
|||
TypedValue::Ref(entids::DB_TYPE_BOOLEAN) => { builder.value_type(ValueType::Boolean); },
|
||||
TypedValue::Ref(entids::DB_TYPE_DOUBLE) => { builder.value_type(ValueType::Double); },
|
||||
TypedValue::Ref(entids::DB_TYPE_LONG) => { builder.value_type(ValueType::Long); },
|
||||
TypedValue::Ref(entids::DB_TYPE_INSTANT) => { builder.value_type(ValueType::Instant); },
|
||||
TypedValue::Ref(entids::DB_TYPE_STRING) => { builder.value_type(ValueType::String); },
|
||||
TypedValue::Ref(entids::DB_TYPE_UUID) => { builder.value_type(ValueType::Uuid); },
|
||||
TypedValue::Ref(entids::DB_TYPE_KEYWORD) => { builder.value_type(ValueType::Keyword); },
|
||||
|
|
Loading…
Reference in a new issue