Skip to content

Commit

Permalink
Fix an issue that disallowed using copy_from with more than 12 column
Browse files Browse the repository at this point in the history
This commit relaxes a trait constraint that restricted our copy from
implementation for `Insertable` types to 12 columns. That happened
because we used the `Default` impl for tuples from the rust standard
library to construct the column types internally. The standard library
only provides these impl for up to 12 tuple elements. 

The fix is to simply construct that type by calling `Default` for each
of the column types seperatly and then constructing the tuple from that.

I choose to not write a test for that as it doesn't change functionality
in any meaningful way other than just allowing larger tuples.
  • Loading branch information
weiznich committed Feb 14, 2025
1 parent 6e4ee3d commit 7d88445
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions diesel/src/pg/query_builder/copy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ macro_rules! copy_target_for_columns {
$(
impl<T, $($ST,)*> CopyTarget for ($($ST,)*)
where
$($ST: Column<Table = T>,)*
$($ST: Column<Table = T> + Default,)*
($(<$ST as Expression>::SqlType,)*): SqlType,
T: Table + StaticQueryFragment,
T::Component: QueryFragment<Pg>,
Self: ColumnList + Default,
Self: ColumnList,
{
type Table = T;
type SqlType = crate::dsl::SqlTypeOf<Self>;
Expand All @@ -162,7 +162,7 @@ macro_rules! copy_target_for_columns {
) -> crate::QueryResult<()> {
T::STATIC_COMPONENT.walk_ast(pass.reborrow())?;
pass.push_sql("(");
<Self as ColumnList>::walk_ast(&Self::default(), pass.reborrow())?;
<Self as ColumnList>::walk_ast(&($($ST::default(),)*), pass.reborrow())?;
pass.push_sql(")");
Ok(())
}
Expand Down

0 comments on commit 7d88445

Please sign in to comment.