feat(mysql): impl Decode for str and String

This commit is contained in:
Ryan Leckey 2021-02-12 14:56:25 -08:00
parent ca7e138b68
commit 5a75655bdf
No known key found for this signature in database
GPG Key ID: F8AA68C235AB08C9
2 changed files with 42 additions and 0 deletions

View File

@ -27,6 +27,7 @@
//!
mod bool;
mod str;
mod uint;
// TODO: mod decimal;

View File

@ -0,0 +1,41 @@
use bytes::Buf;
use sqlx_core::database::HasOutput;
use sqlx_core::{decode, encode};
use sqlx_core::{Database, Decode, Encode};
use crate::type_info::MySqlTypeInfo;
use crate::MySqlRawValueFormat::*;
use crate::{MySql, MySqlOutput, MySqlRawValue, MySqlTypeId};
// https://dev.mysql.com/doc/internals/en/binary-protocol-value.html#packet-ProtocolBinary
// TODO: accepts(ty)
// TODO: compatible(ty)
impl Encode<MySql> for str {
fn encode(&self, _: &MySqlTypeInfo, out: &mut MySqlOutput<'_>) -> encode::Result<()> {
todo!("encode: &str");
Ok(())
}
}
impl Encode<MySql> for String {
fn encode(&self, _: &MySqlTypeInfo, out: &mut MySqlOutput<'_>) -> encode::Result<()> {
todo!("encode: String");
Ok(())
}
}
impl<'r> Decode<'r, MySql> for &'r str {
fn decode(value: MySqlRawValue<'r>) -> decode::Result<Self> {
value.as_str()
}
}
impl<'r> Decode<'r, MySql> for String {
fn decode(value: MySqlRawValue<'r>) -> decode::Result<Self> {
value.as_str().map(str::to_owned)
}
}