mirror of
				https://github.com/launchbadge/sqlx.git
				synced 2025-11-04 07:22:53 +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
					
				@ -22,7 +22,7 @@ pub(crate) enum DataType {
 | 
				
			|||||||
    // non-standard extensions
 | 
					    // non-standard extensions
 | 
				
			||||||
    Bool,
 | 
					    Bool,
 | 
				
			||||||
    Int64,
 | 
					    Int64,
 | 
				
			||||||
    Timestamp,
 | 
					    Datetime,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Type information for a SQLite type.
 | 
					/// Type information for a SQLite type.
 | 
				
			||||||
@ -48,7 +48,7 @@ impl TypeInfo for SqliteTypeInfo {
 | 
				
			|||||||
            // non-standard extensions
 | 
					            // non-standard extensions
 | 
				
			||||||
            DataType::Bool => "BOOLEAN",
 | 
					            DataType::Bool => "BOOLEAN",
 | 
				
			||||||
            DataType::Int64 => "BIGINT",
 | 
					            DataType::Int64 => "BIGINT",
 | 
				
			||||||
            DataType::Timestamp => "TIMESTAMP",
 | 
					            DataType::Datetime => "DATETIME",
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -78,6 +78,7 @@ impl FromStr for DataType {
 | 
				
			|||||||
        Ok(match &*s {
 | 
					        Ok(match &*s {
 | 
				
			||||||
            "int8" => DataType::Int64,
 | 
					            "int8" => DataType::Int64,
 | 
				
			||||||
            "boolean" | "bool" => DataType::Bool,
 | 
					            "boolean" | "bool" => DataType::Bool,
 | 
				
			||||||
 | 
					            "datetime" | "timestamp" => DataType::Datetime,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            _ if s.contains("int") && s.contains("big") && s.find("int") > s.find("big") => {
 | 
					            _ if s.contains("int") && s.contains("big") && s.find("int") > s.find("big") => {
 | 
				
			||||||
                DataType::Int64
 | 
					                DataType::Int64
 | 
				
			||||||
@ -123,7 +124,7 @@ fn test_data_type_from_str() -> Result<(), BoxDynError> {
 | 
				
			|||||||
    assert_eq!(DataType::Bool, "BOOLEAN".parse()?);
 | 
					    assert_eq!(DataType::Bool, "BOOLEAN".parse()?);
 | 
				
			||||||
    assert_eq!(DataType::Bool, "BOOL".parse()?);
 | 
					    assert_eq!(DataType::Bool, "BOOL".parse()?);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert_eq!(DataType::Timestamp, "TIMESTAMP".parse()?);
 | 
					    assert_eq!(DataType::Datetime, "DATETIME".parse()?);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Ok(())
 | 
					    Ok(())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -9,7 +9,7 @@ use chrono::prelude::*;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
impl Type<Sqlite> for NaiveDateTime {
 | 
					impl Type<Sqlite> for NaiveDateTime {
 | 
				
			||||||
    fn type_info() -> SqliteTypeInfo {
 | 
					    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> {
 | 
					impl<Tz: TimeZone> Type<Sqlite> for DateTime<Tz> {
 | 
				
			||||||
    fn type_info() -> SqliteTypeInfo {
 | 
					    fn type_info() -> SqliteTypeInfo {
 | 
				
			||||||
        SqliteTypeInfo(DataType::Timestamp)
 | 
					        SqliteTypeInfo(DataType::Datetime)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -19,7 +19,9 @@
 | 
				
			|||||||
//!
 | 
					//!
 | 
				
			||||||
//! | Rust type                             | Sqlite type(s)                                        |
 | 
					//! | Rust type                             | Sqlite type(s)                                        |
 | 
				
			||||||
//! |---------------------------------------|------------------------------------------------------|
 | 
					//! |---------------------------------------|------------------------------------------------------|
 | 
				
			||||||
//! | `chrono::NaiveDateTime`               | TIMESTAMP                                             |
 | 
					//! | `chrono::NaiveDateTime`               | DATETIME                                             |
 | 
				
			||||||
 | 
					//! | `chrono::DateTime<Utc>`               | DATETIME                                             |
 | 
				
			||||||
 | 
					//! | `chrono::DateTime<Local>`             | DATETIME                                             |
 | 
				
			||||||
//!
 | 
					//!
 | 
				
			||||||
//! # Nullable
 | 
					//! # Nullable
 | 
				
			||||||
//!
 | 
					//!
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user