Skip to content

Use a temp table for encode_many #6

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

Closed
wants to merge 6 commits into from

Conversation

sfackler
Copy link
Member

Just using IN will be faster for small numbers of crates, so you might
want to switch implementations depending on crates.len(). The best
solution would be to use COPY, but I haven't implemented that yet.

I haven't actually tested this, but it compiles!

Just using IN will be faster for small numbers of crates, so you might
want to switch implementations depending on crates.len(). The best
solution would be to use COPY, but I haven't implemented that yet.

I haven't actually tested this, but it compiles!
let mut query = "INSERT INTO crateids (id) VALUES (".to_string();
let mut crateids: Vec<&ToSql> = vec![];
for (i, krate) in crates.iter().enumerate() {
query.push_str(format!("${}", i+1).as_slice());
Copy link
Member

Choose a reason for hiding this comment

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

Is this meant to build a query that looks like ... VALUES ($1$2$3...$n) ... or should there be spaces/commas too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Derp.

Copy link
Member

Choose a reason for hiding this comment

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

Also, this could theoretically use a writer to avoid the format! temporary strings.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed that as well, thanks

@sfackler
Copy link
Member Author

BTW, bad things will happen if crates is empty or has duplicate values.

@alexcrichton
Copy link
Member

For now that list should always be small enough (on the order of at most 100), so I don't think we need this quite yet. That being said, this is a pretty slick way to do thing that I've never heard of before! I'll be sure to remember this for later queries, thanks @sfackler!

Turbo87 pushed a commit that referenced this pull request Dec 8, 2022
Bump to latest conduit alpha and use `http` types
Turbo87 pushed a commit that referenced this pull request Jan 4, 2023
Bump to latest conduit alpha and use `http` types
Turbo87 pushed a commit that referenced this pull request Jan 4, 2023
Bump to latest conduit alpha and use `http` types
Turbo87 pushed a commit that referenced this pull request Jan 4, 2023
Add support for changes to `conduit::Body`
Turbo87 pushed a commit that referenced this pull request Jan 4, 2023
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.

3 participants