Skip to content

Make it possible to use copy_from/copy_to with dynamic tables #4549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lutter
Copy link

@lutter lutter commented Mar 21, 2025

Previously, copy_from and copy_to would only be possible with tables known at compile time. It is now possible to also use them with tables that are only known at runtime. That is achieved by changing the signature of CopyTarget::walk_target to take a self argument.

A couple things I am not sure about with this PR, but more than happy to address:

  1. Since this only changes some internal method signatures, does it need additional tests?
  2. Should the docs for CopyTarget mention anything about tables only known at runtime, as that's a very niche use case?
  3. I had to resort to using an Rc - I hope that's not a big issue

Previously, copy_from and copy_to would only be possible with tables known
at compile time. It is now possible to also use them with tables that are
only known at runtime. That is achieved by changing the signature of
`CopyTarget::walk_target` to take a `self` argument.
@weiznich weiznich requested a review from a team March 21, 2025 20:18
Copy link
Member

@weiznich weiznich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this PR ❤️

Using an Rc there is unfortunately not possible, but should be easy to avoid.

Since this only changes some internal method signatures, does it need additional tests?
Should the docs for CopyTarget mention anything about tables only known at runtime, as that's a very niche use case?

I would prefer having an explicit example here to ensure that we don't break this again. That would serve as test + documentation together.

@@ -372,7 +377,7 @@ where
#[must_use = "`COPY FROM` statements are only executed when calling `.execute()`."]
#[cfg(feature = "postgres_backend")]
pub struct CopyFromQuery<T, Action> {
table: T,
table: Rc<T>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an Rc here is unfortunately a breaking change as this turns this struct from something that implements Send into something that doesn't implement Send.

Fortunately we don't need to explicitly store table inside of InsertableWrapper. Instead we can just pass a reference in through the method call chain.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I'll incorporate it, but it might take me a little bit to get around to it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants