Use DATETIME for Sqlite chrono, fix parsing and docs.

The name DATETIME is used as an example by the SQLite documentation
(https://sqlite.org/datatype3.html#affinity).
This commit is contained in:
Felipe Lessa 2020-06-27 12:22:27 +01:00
parent f0adeae39e
commit 30faf73208
No known key found for this signature in database
GPG key ID: 210DC649890C2FEA
3 changed files with 9 additions and 6 deletions

View file

@ -22,7 +22,7 @@ pub(crate) enum DataType {
// non-standard extensions
Bool,
Int64,
Timestamp,
Datetime,
}
/// Type information for a SQLite type.
@ -48,7 +48,7 @@ impl TypeInfo for SqliteTypeInfo {
// non-standard extensions
DataType::Bool => "BOOLEAN",
DataType::Int64 => "BIGINT",
DataType::Timestamp => "TIMESTAMP",
DataType::Datetime => "DATETIME",
}
}
}
@ -78,6 +78,7 @@ impl FromStr for DataType {
Ok(match &*s {
"int8" => DataType::Int64,
"boolean" | "bool" => DataType::Bool,
"datetime" | "timestamp" => DataType::Datetime,
_ if s.contains("int") && s.contains("big") && s.find("int") > s.find("big") => {
DataType::Int64
@ -123,7 +124,7 @@ fn test_data_type_from_str() -> Result<(), BoxDynError> {
assert_eq!(DataType::Bool, "BOOLEAN".parse()?);
assert_eq!(DataType::Bool, "BOOL".parse()?);
assert_eq!(DataType::Timestamp, "TIMESTAMP".parse()?);
assert_eq!(DataType::Datetime, "DATETIME".parse()?);
Ok(())
}

View file

@ -9,7 +9,7 @@ use chrono::prelude::*;
impl Type<Sqlite> for NaiveDateTime {
fn type_info() -> SqliteTypeInfo {
SqliteTypeInfo(DataType::Timestamp)
SqliteTypeInfo(DataType::Datetime)
}
}
@ -57,7 +57,7 @@ fn decode_naive_from_text(text: &str) -> Result<NaiveDateTime, BoxDynError> {
impl<Tz: TimeZone> Type<Sqlite> for DateTime<Tz> {
fn type_info() -> SqliteTypeInfo {
SqliteTypeInfo(DataType::Timestamp)
SqliteTypeInfo(DataType::Datetime)
}
}

View file

@ -19,7 +19,9 @@
//!
//! | Rust type | Sqlite type(s) |
//! |---------------------------------------|------------------------------------------------------|
//! | `chrono::NaiveDateTime` | TIMESTAMP |
//! | `chrono::NaiveDateTime` | DATETIME |
//! | `chrono::DateTime<Utc>` | DATETIME |
//! | `chrono::DateTime<Local>` | DATETIME |
//!
//! # Nullable
//!