mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-04-14 00:10:13 +00:00
macros + sqlite: fix error for null-typed columns
This commit is contained in:
committed by
Ryan Leckey
parent
2a76123bc3
commit
8328e07c97
@@ -106,6 +106,10 @@ impl TypeInfo for MySqlTypeInfo {
|
||||
_ => self.id.0 == other.id.0 && self.is_unsigned == other.is_unsigned,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_null_type(&self) -> bool {
|
||||
self.id == TypeId::NULL
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, T> Decode<'de, MySql> for Option<T>
|
||||
|
||||
@@ -81,6 +81,11 @@ impl TypeInfo for PgTypeInfo {
|
||||
// TODO: 99% of postgres types are direct equality for [compatible]; when we add something that isn't (e.g, JSON/JSONB), fix this here
|
||||
self.id.0 == other.id.0
|
||||
}
|
||||
|
||||
fn is_null_type(&self) -> bool {
|
||||
// Postgres doesn't have a "null" type
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, T> Decode<'de, Postgres> for Option<T>
|
||||
|
||||
@@ -66,6 +66,10 @@ impl TypeInfo for SqliteTypeInfo {
|
||||
fn compatible(&self, other: &Self) -> bool {
|
||||
self.affinity == other.affinity
|
||||
}
|
||||
|
||||
fn is_null_type(&self) -> bool {
|
||||
self.r#type == SqliteType::Null
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, T> Decode<'de, Sqlite> for Option<T>
|
||||
|
||||
@@ -18,6 +18,14 @@ pub trait TypeInfo: Debug + Display + Clone {
|
||||
/// Compares type information to determine if `other` is compatible at the Rust level
|
||||
/// with `self`.
|
||||
fn compatible(&self, other: &Self) -> bool;
|
||||
|
||||
/// Return `true` if this is the database flavor's "null" sentinel type.
|
||||
///
|
||||
/// For type info coming from the description of a prepared statement, this means
|
||||
/// that the server could not infer the expected type of a bind parameter or result column;
|
||||
/// the latter is most often the case with columns that are the result of an expression
|
||||
/// in a weakly-typed database like MySQL or SQLite.
|
||||
fn is_null_type(&self) -> bool;
|
||||
}
|
||||
|
||||
/// Indicates that a SQL type is supported for a database.
|
||||
|
||||
Reference in New Issue
Block a user