Skip to content

Commit

Permalink
Workaround for #33
Browse files Browse the repository at this point in the history
  • Loading branch information
gammelalf committed Dec 28, 2022
1 parent 34f8022 commit b871165
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rorm-db
Submodule rorm-db updated 1 files
+8 −0 src/row.rs
18 changes: 18 additions & 0 deletions rorm-macro/src/trait_impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ pub fn try_from_row(
)*
})
}
fn from_row_using_position(row: ::rorm::row::Row) -> Result<Self, ::rorm::Error> {
let mut i: isize = -1;
Ok(#strct {
#(
#fields: {
if <Self as ::rorm::model::Patch>::Model::FIELDS.#fields.name().is_some() {
i += 1;
<#model as ::rorm::model::Model>::FIELDS.#fields.get_from_row(&row, Some(i as usize))?
} else {
<#model as ::rorm::model::Model>::FIELDS.#fields.get_from_row(&row, Option::<usize>::None)?
}
},
)*
#(
#ignored: Default::default(),
)*
})
}
}
}
}
2 changes: 1 addition & 1 deletion rorm-sql
Submodule rorm-sql updated 1 files
+1 −1 src/value.rs
26 changes: 12 additions & 14 deletions src/crud/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ impl<M: Model> Returning<M> for PrimaryKey<M> {
type Result = <M::Primary as Field>::Type;

fn decode(row: Row) -> Result<Self::Result, Error> {
Ok(<M::Primary as Field>::Type::from_primitive(
row.get(M::Primary::NAME)?,
))
Ok(<M::Primary as Field>::Type::from_primitive(row.get(0)?))
}

fn columns(&self) -> &[&'static str] {
Expand Down Expand Up @@ -282,7 +280,7 @@ impl<M: Model, P: Patch<Model = M>> Returning<M> for ReturnPatch<P> {
type Result = P;

fn decode(row: Row) -> Result<Self::Result, Error> {
P::from_row(row)
P::from_row_using_position(row)
}

fn columns(&self) -> &[&'static str] {
Expand All @@ -299,7 +297,7 @@ pub struct ReturnTuple<T, const C: usize> {
columns: [&'static str; C],
}
macro_rules! impl_select_tuple {
($C:literal, ($($F:ident,)+)) => {
($C:literal, ($($F:ident @ $i:literal),+)) => {
impl<$($F: Field),+> From<($(FieldProxy<$F, $F::Model>,)+)> for ReturnTuple<($(FieldProxy<$F, $F::Model>,)+), $C> {
fn from(tuple: ($(FieldProxy<$F, $F::Model>,)+)) -> Self {
Self {
Expand All @@ -318,7 +316,7 @@ macro_rules! impl_select_tuple {

fn decode(row: Row) -> Result<Self::Result, Error> {
Ok(($(
$F::Type::from_primitive(row.get($F::NAME)?),
$F::Type::from_primitive(row.get($i)?),
)+))
}

Expand All @@ -328,11 +326,11 @@ macro_rules! impl_select_tuple {
}
};
}
impl_select_tuple!(1, (S0,));
impl_select_tuple!(2, (S0, S1,));
impl_select_tuple!(3, (S0, S1, S2,));
impl_select_tuple!(4, (S0, S1, S2, S3,));
impl_select_tuple!(5, (S0, S1, S2, S3, S4,));
impl_select_tuple!(6, (S0, S1, S2, S3, S4, S5,));
impl_select_tuple!(7, (S0, S1, S2, S3, S4, S5, S6,));
impl_select_tuple!(8, (S0, S1, S2, S3, S4, S5, S6, S7,));
impl_select_tuple!(1, (A @ 0));
impl_select_tuple!(2, (A @ 0, B @ 1));
impl_select_tuple!(3, (A @ 0, B @ 1, C @ 2));
impl_select_tuple!(4, (A @ 0, B @ 1, C @ 2, D @ 3));
impl_select_tuple!(5, (A @ 0, B @ 1, C @ 2, D @ 3, E @ 4));
impl_select_tuple!(6, (A @ 0, B @ 1, C @ 2, D @ 3, E @ 4, F @ 5));
impl_select_tuple!(7, (A @ 0, B @ 1, C @ 2, D @ 3, E @ 4, F @ 5, G @ 6));
impl_select_tuple!(8, (A @ 0, B @ 1, C @ 2, D @ 3, E @ 4, F @ 5, G @ 6, H @ 7));

0 comments on commit b871165

Please sign in to comment.