Merge pull request #24 from mehcode/ab/codec

rename `FromSql/ToSql` -> `Decode/Encode`
This commit is contained in:
Ryan Leckey 2019-11-22 13:40:45 +00:00 committed by GitHub
commit 8bd768afe8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 156 additions and 156 deletions

18
sqlx-core/src/decode.rs Normal file
View file

@ -0,0 +1,18 @@
//! Types and traits related to deserializing values from the database.
use crate::{backend::Backend, types::HasSqlType};
// TODO: Allow decode to return an error (that can be unified)
pub trait Decode<DB: Backend> {
fn decode(raw: Option<&[u8]>) -> Self;
}
impl<T, DB> Decode<DB> for Option<T>
where
DB: Backend + HasSqlType<T>,
T: Decode<DB>,
{
fn decode(raw: Option<&[u8]>) -> Self {
Some(T::decode(Some(raw?)))
}
}

View file

@ -1,18 +0,0 @@
//! Types and traits related to deserializing values from the database.
use crate::{backend::Backend, types::HasSqlType};
// TODO: Allow from_sql to return an error (that can be unified)
pub trait FromSql<DB: Backend> {
fn from_sql(raw: Option<&[u8]>) -> Self;
}
impl<T, DB> FromSql<DB> for Option<T>
where
DB: Backend + HasSqlType<T>,
T: FromSql<DB>,
{
fn from_sql(raw: Option<&[u8]>) -> Self {
Some(T::from_sql(Some(raw?)))
}
}

View file

@ -1,7 +1,7 @@
//! Types and traits related to serializing values for the database.
use crate::{backend::Backend, types::HasSqlType};
/// Annotates the result of [ToSql] to differentiate between an empty value and a null value.
/// Annotates the result of [Encode] to differentiate between an empty value and a null value.
pub enum IsNull {
/// The value was null (and no data was written to the buffer).
Yes,
@ -19,39 +19,39 @@ pub enum IsNull {
///
/// When possible, implementations of this trait should prefer using an
/// existing implementation, rather than writing to `buf` directly.
pub trait ToSql<DB: Backend> {
pub trait Encode<DB: Backend> {
/// Writes the value of `self` into `buf` as the expected format
/// for the given backend.
///
/// The return value indicates if this value should be represented as `NULL`.
/// If this is the case, implementations **must not** write anything to `out`.
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull;
fn encode(&self, buf: &mut Vec<u8>) -> IsNull;
}
/// [ToSql] is implemented for `Option<T>` where `T` implements `ToSql`. An `Option<T>`
/// [Encode] is implemented for `Option<T>` where `T` implements `Encode`. An `Option<T>`
/// represents a nullable SQL value.
impl<T, DB> ToSql<DB> for Option<T>
impl<T, DB> Encode<DB> for Option<T>
where
DB: Backend + HasSqlType<T>,
T: ToSql<DB>,
T: Encode<DB>,
{
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
if let Some(self_) = self {
self_.to_sql(buf)
self_.encode(buf)
} else {
IsNull::Yes
}
}
}
impl<T: ?Sized, DB> ToSql<DB> for &'_ T
impl<T: ?Sized, DB> Encode<DB> for &'_ T
where
DB: Backend + HasSqlType<T>,
T: ToSql<DB>,
T: Encode<DB>,
{
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
(*self).to_sql(buf)
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
(*self).encode(buf)
}
}

View file

@ -9,7 +9,7 @@ pub mod error;
mod io;
mod backend;
pub mod deserialize;
pub mod decode;
#[cfg(any(feature = "postgres", feature = "mariadb"))]
mod url;
@ -24,7 +24,7 @@ mod pool;
#[macro_use]
pub mod query;
pub mod serialize;
pub mod encode;
mod sql;
pub mod types;
@ -37,12 +37,12 @@ pub use self::{
backend::Backend,
compiled::CompiledSql,
connection::Connection,
deserialize::FromSql,
decode::Decode,
error::{Error, Result},
executor::Executor,
pool::Pool,
row::{FromSqlRow, Row},
serialize::ToSql,
encode::Encode,
sql::{query, SqlQuery},
types::HasSqlType,
};

View file

@ -2,7 +2,7 @@ use super::MariaDb;
use crate::{
mariadb::types::MariaDbTypeMetadata,
query::QueryParameters,
serialize::{IsNull, ToSql},
encode::{IsNull, Encode},
types::HasSqlType,
};
@ -27,14 +27,14 @@ impl QueryParameters for MariaDbQueryParameters {
where
Self: Sized,
Self::Backend: HasSqlType<T>,
T: ToSql<Self::Backend>,
T: Encode<Self::Backend>,
{
let metadata = <MariaDb as HasSqlType<T>>::metadata();
let index = self.param_types.len();
self.param_types.push(metadata);
if let IsNull::Yes = value.to_sql(&mut self.params) {
if let IsNull::Yes = value.encode(&mut self.params) {
self.null[index / 8] = self.null[index / 8] & (1 << index % 8);
}
}

View file

@ -3,8 +3,8 @@ use crate::{
protocol::{FieldType, ParameterFlag},
types::MariaDbTypeMetadata,
},
serialize::IsNull,
FromSql, HasSqlType, MariaDb, ToSql,
encode::IsNull,
Decode, HasSqlType, MariaDb, Encode,
};
impl HasSqlType<[u8]> for MariaDb {
@ -22,21 +22,21 @@ impl HasSqlType<Vec<u8>> for MariaDb {
}
}
impl ToSql<MariaDb> for [u8] {
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
impl Encode<MariaDb> for [u8] {
fn encode(&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 Encode<MariaDb> for Vec<u8> {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
<[u8] as Encode<MariaDb>>::to_sql(self, buf)
}
}
impl FromSql<MariaDb> for Vec<u8> {
fn from_sql(raw: Option<&[u8]>) -> Self {
impl Decode<MariaDb> for Vec<u8> {
fn decode(raw: Option<&[u8]>) -> Self {
raw.unwrap().into()
}
}

View file

@ -1,8 +1,8 @@
use super::{MariaDb, MariaDbTypeMetadata};
use crate::{
deserialize::FromSql,
decode::Decode,
mariadb::protocol::{FieldType, ParameterFlag},
serialize::{IsNull, ToSql},
encode::{IsNull, Encode},
types::HasSqlType,
};
@ -16,18 +16,18 @@ impl HasSqlType<bool> for MariaDb {
}
}
impl ToSql<MariaDb> for bool {
impl Encode<MariaDb> for bool {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
buf.push(*self as u8);
IsNull::No
}
}
impl FromSql<MariaDb> for bool {
impl Decode<MariaDb> for bool {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
fn decode(buf: Option<&[u8]>) -> Self {
// TODO: Handle optionals
buf.unwrap()[0] != 0
}

View file

@ -1,8 +1,8 @@
use super::{MariaDb, MariaDbTypeMetadata};
use crate::{
deserialize::FromSql,
decode::Decode,
mariadb::protocol::{FieldType, ParameterFlag},
serialize::{IsNull, ToSql},
encode::{IsNull, Encode},
types::HasSqlType,
};
use std::str;
@ -25,25 +25,25 @@ impl HasSqlType<String> for MariaDb {
}
}
impl ToSql<MariaDb> for str {
impl Encode<MariaDb> for str {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
buf.extend_from_slice(self.as_bytes());
IsNull::No
}
}
impl ToSql<MariaDb> for String {
impl Encode<MariaDb> for String {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
<str as ToSql<MariaDb>>::to_sql(self.as_str(), buf)
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
<str as Encode<MariaDb>>::to_sql(self.as_str(), buf)
}
}
impl FromSql<MariaDb> for String {
impl Decode<MariaDb> for String {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
fn decode(buf: Option<&[u8]>) -> Self {
// TODO: Handle nulls
let s = if cfg!(debug_assertions) {

View file

@ -1,8 +1,8 @@
use super::{MariaDb, MariaDbTypeMetadata};
use crate::{
deserialize::FromSql,
decode::Decode,
mariadb::protocol::{FieldType, ParameterFlag},
serialize::{IsNull, ToSql},
encode::{IsNull, Encode},
types::HasSqlType,
};
use byteorder::{BigEndian, ByteOrder};
@ -18,18 +18,18 @@ impl HasSqlType<i16> for MariaDb {
}
}
impl ToSql<MariaDb> for i16 {
impl Encode<MariaDb> for i16 {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
buf.extend_from_slice(&self.to_be_bytes());
IsNull::No
}
}
impl FromSql<MariaDb> for i16 {
impl Decode<MariaDb> for i16 {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
fn decode(buf: Option<&[u8]>) -> Self {
BigEndian::read_i16(buf.unwrap())
}
}
@ -45,18 +45,18 @@ impl HasSqlType<i32> for MariaDb {
}
}
impl ToSql<MariaDb> for i32 {
impl Encode<MariaDb> for i32 {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
buf.extend_from_slice(&self.to_be_bytes());
IsNull::No
}
}
impl FromSql<MariaDb> for i32 {
impl Decode<MariaDb> for i32 {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
fn decode(buf: Option<&[u8]>) -> Self {
BigEndian::read_i32(buf.unwrap())
}
}
@ -72,18 +72,18 @@ impl HasSqlType<i64> for MariaDb {
}
}
impl ToSql<MariaDb> for i64 {
impl Encode<MariaDb> for i64 {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
buf.extend_from_slice(&self.to_be_bytes());
IsNull::No
}
}
impl FromSql<MariaDb> for i64 {
impl Decode<MariaDb> for i64 {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
fn decode(buf: Option<&[u8]>) -> Self {
BigEndian::read_i64(buf.unwrap())
}
}
@ -99,17 +99,17 @@ impl HasSqlType<f32> for MariaDb {
}
}
impl ToSql<MariaDb> for f32 {
impl Encode<MariaDb> for f32 {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
<i32 as ToSql<MariaDb>>::to_sql(&(self.to_bits() as i32), buf)
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
<i32 as Encode<MariaDb>>::to_sql(&(self.to_bits() as i32), buf)
}
}
impl FromSql<MariaDb> for f32 {
impl Decode<MariaDb> for f32 {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
f32::from_bits(<i32 as FromSql<MariaDb>>::from_sql(buf) as u32)
fn decode(buf: Option<&[u8]>) -> Self {
f32::from_bits(<i32 as Decode<MariaDb>>::from_sql(buf) as u32)
}
}
@ -124,16 +124,16 @@ impl HasSqlType<f64> for MariaDb {
}
}
impl ToSql<MariaDb> for f64 {
impl Encode<MariaDb> for f64 {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
<i64 as ToSql<MariaDb>>::to_sql(&(self.to_bits() as i64), buf)
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
<i64 as Encode<MariaDb>>::to_sql(&(self.to_bits() as i64), buf)
}
}
impl FromSql<MariaDb> for f64 {
impl Decode<MariaDb> for f64 {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
f64::from_bits(<i64 as FromSql<MariaDb>>::from_sql(buf) as u64)
fn decode(buf: Option<&[u8]>) -> Self {
f64::from_bits(<i64 as Decode<MariaDb>>::from_sql(buf) as u64)
}
}

View file

@ -2,7 +2,7 @@ use super::Postgres;
use crate::{
io::BufMut,
query::QueryParameters,
serialize::{IsNull, ToSql},
encode::{IsNull, Encode},
types::HasSqlType,
};
use byteorder::{BigEndian, ByteOrder, NetworkEndian};
@ -30,7 +30,7 @@ impl QueryParameters for PostgresQueryParameters {
where
Self: Sized,
Self::Backend: HasSqlType<T>,
T: ToSql<Self::Backend>,
T: Encode<Self::Backend>,
{
// TODO: When/if we receive types that do _not_ support BINARY, we need to check here
// TODO: There is no need to be explicit unless we are expecting mixed BINARY / TEXT
@ -40,7 +40,7 @@ impl QueryParameters for PostgresQueryParameters {
let pos = self.buf.len();
self.buf.put_i32::<NetworkEndian>(0);
let len = if let IsNull::No = value.to_sql(&mut self.buf) {
let len = if let IsNull::No = value.encode(&mut self.buf) {
(self.buf.len() - pos - 4) as i32
} else {
// Write a -1 for the len to indicate NULL

View file

@ -1,7 +1,7 @@
use crate::{
postgres::types::{PostgresTypeFormat, PostgresTypeMetadata},
serialize::IsNull,
FromSql, HasSqlType, Postgres, ToSql,
encode::IsNull,
Decode, HasSqlType, Postgres, Encode,
};
impl HasSqlType<[u8]> for Postgres {
@ -20,21 +20,21 @@ impl HasSqlType<Vec<u8>> for Postgres {
}
}
impl ToSql<Postgres> for [u8] {
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
impl Encode<Postgres> for [u8] {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
buf.extend_from_slice(self);
IsNull::No
}
}
impl ToSql<Postgres> for Vec<u8> {
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
<[u8] as ToSql<Postgres>>::to_sql(self, buf)
impl Encode<Postgres> for Vec<u8> {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
<[u8] as Encode<Postgres>>::to_sql(self, buf)
}
}
impl FromSql<Postgres> for Vec<u8> {
fn from_sql(raw: Option<&[u8]>) -> Self {
impl Decode<Postgres> for Vec<u8> {
fn decode(raw: Option<&[u8]>) -> Self {
raw.unwrap().into()
}
}

View file

@ -1,7 +1,7 @@
use super::{Postgres, PostgresTypeFormat, PostgresTypeMetadata};
use crate::{
deserialize::FromSql,
serialize::{IsNull, ToSql},
decode::Decode,
encode::{IsNull, Encode},
types::HasSqlType,
};
@ -15,18 +15,18 @@ impl HasSqlType<bool> for Postgres {
}
}
impl ToSql<Postgres> for bool {
impl Encode<Postgres> for bool {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
buf.push(*self as u8);
IsNull::No
}
}
impl FromSql<Postgres> for bool {
impl Decode<Postgres> for bool {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
fn decode(buf: Option<&[u8]>) -> Self {
// TODO: Handle optionals
buf.unwrap()[0] != 0
}

View file

@ -1,7 +1,7 @@
use super::{Postgres, PostgresTypeFormat, PostgresTypeMetadata};
use crate::{
deserialize::FromSql,
serialize::{IsNull, ToSql},
decode::Decode,
encode::{IsNull, Encode},
types::HasSqlType,
};
use std::str;
@ -24,25 +24,25 @@ impl HasSqlType<String> for Postgres {
}
}
impl ToSql<Postgres> for str {
impl Encode<Postgres> for str {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
buf.extend_from_slice(self.as_bytes());
IsNull::No
}
}
impl ToSql<Postgres> for String {
impl Encode<Postgres> for String {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
<str as ToSql<Postgres>>::to_sql(self.as_str(), buf)
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
<str as Encode<Postgres>>::to_sql(self.as_str(), buf)
}
}
impl FromSql<Postgres> for String {
impl Decode<Postgres> for String {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
fn decode(buf: Option<&[u8]>) -> Self {
// TODO: Handle nulls
let s = if cfg!(debug_assertions) {

View file

@ -1,7 +1,7 @@
use super::{Postgres, PostgresTypeFormat, PostgresTypeMetadata};
use crate::{
deserialize::FromSql,
serialize::{IsNull, ToSql},
decode::Decode,
encode::{IsNull, Encode},
types::HasSqlType,
};
use byteorder::{BigEndian, ByteOrder};
@ -17,18 +17,18 @@ impl HasSqlType<i16> for Postgres {
}
}
impl ToSql<Postgres> for i16 {
impl Encode<Postgres> for i16 {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
buf.extend_from_slice(&self.to_be_bytes());
IsNull::No
}
}
impl FromSql<Postgres> for i16 {
impl Decode<Postgres> for i16 {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
fn decode(buf: Option<&[u8]>) -> Self {
BigEndian::read_i16(buf.unwrap())
}
}
@ -44,18 +44,18 @@ impl HasSqlType<i32> for Postgres {
}
}
impl ToSql<Postgres> for i32 {
impl Encode<Postgres> for i32 {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
buf.extend_from_slice(&self.to_be_bytes());
IsNull::No
}
}
impl FromSql<Postgres> for i32 {
impl Decode<Postgres> for i32 {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
fn decode(buf: Option<&[u8]>) -> Self {
BigEndian::read_i32(buf.unwrap())
}
}
@ -71,18 +71,18 @@ impl HasSqlType<i64> for Postgres {
}
}
impl ToSql<Postgres> for i64 {
impl Encode<Postgres> for i64 {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
buf.extend_from_slice(&self.to_be_bytes());
IsNull::No
}
}
impl FromSql<Postgres> for i64 {
impl Decode<Postgres> for i64 {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
fn decode(buf: Option<&[u8]>) -> Self {
BigEndian::read_i64(buf.unwrap())
}
}
@ -98,17 +98,17 @@ impl HasSqlType<f32> for Postgres {
}
}
impl ToSql<Postgres> for f32 {
impl Encode<Postgres> for f32 {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
<i32 as ToSql<Postgres>>::to_sql(&(self.to_bits() as i32), buf)
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
<i32 as Encode<Postgres>>::to_sql(&(self.to_bits() as i32), buf)
}
}
impl FromSql<Postgres> for f32 {
impl Decode<Postgres> for f32 {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
f32::from_bits(<i32 as FromSql<Postgres>>::from_sql(buf) as u32)
fn decode(buf: Option<&[u8]>) -> Self {
f32::from_bits(<i32 as Decode<Postgres>>::from_sql(buf) as u32)
}
}
@ -123,16 +123,16 @@ impl HasSqlType<f64> for Postgres {
}
}
impl ToSql<Postgres> for f64 {
impl Encode<Postgres> for f64 {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
<i64 as ToSql<Postgres>>::to_sql(&(self.to_bits() as i64), buf)
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
<i64 as Encode<Postgres>>::to_sql(&(self.to_bits() as i64), buf)
}
}
impl FromSql<Postgres> for f64 {
impl Decode<Postgres> for f64 {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
f64::from_bits(<i64 as FromSql<Postgres>>::from_sql(buf) as u64)
fn decode(buf: Option<&[u8]>) -> Self {
f64::from_bits(<i64 as Decode<Postgres>>::from_sql(buf) as u64)
}
}

View file

@ -2,8 +2,8 @@ use uuid::Uuid;
use super::{Postgres, PostgresTypeFormat, PostgresTypeMetadata};
use crate::{
deserialize::FromSql,
serialize::{IsNull, ToSql},
decode::Decode,
encode::{IsNull, Encode},
types::HasSqlType,
};
@ -17,18 +17,18 @@ impl HasSqlType<Uuid> for Postgres {
}
}
impl ToSql<Postgres> for Uuid {
impl Encode<Postgres> for Uuid {
#[inline]
fn to_sql(&self, buf: &mut Vec<u8>) -> IsNull {
fn encode(&self, buf: &mut Vec<u8>) -> IsNull {
buf.extend_from_slice(self.as_bytes());
IsNull::No
}
}
impl FromSql<Postgres> for Uuid {
impl Decode<Postgres> for Uuid {
#[inline]
fn from_sql(buf: Option<&[u8]>) -> Self {
fn decode(buf: Option<&[u8]>) -> Self {
// TODO: Handle optionals, error
Uuid::from_slice(buf.unwrap()).unwrap()
}

View file

@ -1,4 +1,4 @@
use crate::{backend::Backend, serialize::ToSql, types::HasSqlType};
use crate::{backend::Backend, encode::Encode, types::HasSqlType};
pub trait QueryParameters: Send {
type Backend: Backend;
@ -10,7 +10,7 @@ pub trait QueryParameters: Send {
fn bind<T>(&mut self, value: T)
where
Self::Backend: HasSqlType<T>,
T: ToSql<Self::Backend>;
T: Encode<Self::Backend>;
}
pub trait IntoQueryParameters<DB>
@ -26,7 +26,7 @@ macro_rules! impl_into_query_parameters {
impl<$($T,)+> crate::query::IntoQueryParameters<$B> for ($($T,)+)
where
$($B: crate::types::HasSqlType<$T>,)+
$($T: crate::serialize::ToSql<$B>,)+
$($T: crate::encode::Encode<$B>,)+
{
fn into_params(self) -> <$B as crate::backend::Backend>::QueryParameters {
let mut params = <<$B as crate::backend::Backend>::QueryParameters

View file

@ -1,4 +1,4 @@
use crate::{backend::Backend, deserialize::FromSql, types::HasSqlType};
use crate::{backend::Backend, decode::Decode, types::HasSqlType};
pub trait Row: Send {
type Backend: Backend;
@ -13,9 +13,9 @@ pub trait Row: Send {
fn get<T>(&self, index: usize) -> T
where
Self::Backend: HasSqlType<T>,
T: FromSql<Self::Backend>,
T: Decode<Self::Backend>,
{
T::from_sql(self.get_raw(index))
T::decode(self.get_raw(index))
}
}
@ -26,7 +26,7 @@ pub trait FromSqlRow<DB: Backend> {
impl<T, DB> FromSqlRow<DB> for T
where
DB: Backend + HasSqlType<T>,
T: FromSql<DB>,
T: Decode<DB>,
{
#[inline]
fn from_row<R: Row<Backend = DB>>(row: R) -> Self {
@ -40,7 +40,7 @@ macro_rules! impl_from_sql_row_tuple {
impl<$($T,)+> crate::row::FromSqlRow<$B> for ($($T,)+)
where
$($B: crate::types::HasSqlType<$T>,)+
$($T: crate::deserialize::FromSql<$B>,)+
$($T: crate::decode::Decode<$B>,)+
{
#[inline]
fn from_row<R: crate::row::Row<Backend = $B>>(row: R) -> Self {

View file

@ -1,6 +1,6 @@
use crate::{
backend::Backend, error::Error, executor::Executor, query::QueryParameters, row::FromSqlRow,
serialize::ToSql, types::HasSqlType,
encode::Encode, types::HasSqlType,
};
use futures_core::{future::BoxFuture, stream::BoxStream};
@ -26,7 +26,7 @@ where
pub fn bind<T>(mut self, value: T) -> Self
where
DB: HasSqlType<T>,
T: ToSql<DB>,
T: Encode<DB>,
{
self.params.bind(value);
self