mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-02 23:35:20 +00:00
fix FromRow derive to take &Row
This commit is contained in:
parent
e71b969e78
commit
dcea3f0586
@ -31,7 +31,7 @@ where
|
|||||||
impl<'c, R, I> ColumnIndex<'c, R> for &'_ I
|
impl<'c, R, I> ColumnIndex<'c, R> for &'_ I
|
||||||
where
|
where
|
||||||
R: Row<'c>,
|
R: Row<'c>,
|
||||||
I: ColumnIndex<'c, R>,
|
I: ColumnIndex<'c, R> + ?Sized,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index(&self, row: &R) -> crate::Result<<R as Row<'c>>::Database, usize> {
|
fn index(&self, row: &R) -> crate::Result<<R as Row<'c>>::Database, usize> {
|
||||||
@ -44,7 +44,7 @@ mod private_column_index {
|
|||||||
pub trait Sealed {}
|
pub trait Sealed {}
|
||||||
impl Sealed for usize {}
|
impl Sealed for usize {}
|
||||||
impl Sealed for str {}
|
impl Sealed for str {}
|
||||||
impl<T> Sealed for &'_ T where T: Sealed {}
|
impl<T> Sealed for &'_ T where T: Sealed + ?Sized {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a single row from the database.
|
/// Represents a single row from the database.
|
||||||
|
@ -86,7 +86,7 @@ fn expand_derive_from_row_struct(
|
|||||||
|
|
||||||
Ok(quote!(
|
Ok(quote!(
|
||||||
impl #impl_generics sqlx::row::FromRow<#lifetime, R> for #ident #ty_generics #where_clause {
|
impl #impl_generics sqlx::row::FromRow<#lifetime, R> for #ident #ty_generics #where_clause {
|
||||||
fn from_row(row: R) -> sqlx::Result<R::Database, Self> {
|
fn from_row(row: &R) -> sqlx::Result<R::Database, Self> {
|
||||||
#(#reads)*
|
#(#reads)*
|
||||||
|
|
||||||
Ok(#ident {
|
Ok(#ident {
|
||||||
|
@ -125,7 +125,7 @@ async fn test_from_row() -> anyhow::Result<()> {
|
|||||||
.bind(1_i32)
|
.bind(1_i32)
|
||||||
.fetch(&mut conn);
|
.fetch(&mut conn);
|
||||||
|
|
||||||
let account = RefAccount::from_row(cursor.next().await?.unwrap())?;
|
let account = RefAccount::from_row(&cursor.next().await?.unwrap())?;
|
||||||
|
|
||||||
assert_eq!(account.id, 1);
|
assert_eq!(account.id, 1);
|
||||||
assert_eq!(account.name, "Herp Derpinson");
|
assert_eq!(account.name, "Herp Derpinson");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user