mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 14:34:19 +00:00
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:
parent
f0adeae39e
commit
30faf73208
3 changed files with 9 additions and 6 deletions
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
//!
|
||||
//! | Rust type | Sqlite type(s) |
|
||||
//! |---------------------------------------|------------------------------------------------------|
|
||||
//! | `chrono::NaiveDateTime` | TIMESTAMP |
|
||||
//! | `chrono::NaiveDateTime` | DATETIME |
|
||||
//! | `chrono::DateTime<Utc>` | DATETIME |
|
||||
//! | `chrono::DateTime<Local>` | DATETIME |
|
||||
//!
|
||||
//! # Nullable
|
||||
//!
|
||||
|
|
Loading…
Reference in a new issue