mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-02 15:25:32 +00:00
implement binary types for MariaDB
This commit is contained in:
parent
bbdc03c576
commit
22f3d6cae1
38
src/mariadb/types/binary.rs
Normal file
38
src/mariadb/types/binary.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use crate::{HasSqlType, MariaDb, ToSql, FromSql};
|
||||
use crate::mariadb::types::MariaDbTypeMetadata;
|
||||
use crate::mariadb::protocol::{ParameterFlag, FieldType};
|
||||
use crate::serialize::IsNull;
|
||||
|
||||
impl HasSqlType<[u8]> for MariaDb {
|
||||
fn metadata() -> Self::Metadata {
|
||||
MariaDbTypeMetadata {
|
||||
field_type: FieldType::MYSQL_TYPE_BLOB,
|
||||
param_flag: ParameterFlag::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasSqlType<Vec<u8>> for MariaDb {
|
||||
fn metadata() -> Self::Metadata {
|
||||
<Self as HasSqlType<[u8]>>::metadata()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToSql<MariaDb> for [u8] {
|
||||
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
|
||||
buf.extend_from_slice(self);
|
||||
IsNull::No
|
||||
}
|
||||
}
|
||||
|
||||
impl ToSql<MariaDb> for Vec<u8> {
|
||||
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
|
||||
<[u8] as ToSql<MariaDb>>::to_sql(self, buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromSql<MariaDb> for Vec<u8> {
|
||||
fn from_sql(raw: Option<&[u8]>) -> Self {
|
||||
raw.unwrap().into()
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ use crate::{
|
||||
types::{HasTypeMetadata, TypeMetadata},
|
||||
};
|
||||
|
||||
pub mod binary;
|
||||
pub mod boolean;
|
||||
pub mod character;
|
||||
pub mod numeric;
|
||||
|
Loading…
x
Reference in New Issue
Block a user