Skip to content
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

Batched inserts #39

Open
mclrc opened this issue May 1, 2024 · 4 comments
Open

Batched inserts #39

mclrc opened this issue May 1, 2024 · 4 comments

Comments

@mclrc
Copy link

mclrc commented May 1, 2024

Hello! Loving the library, thank you so much!

The only thing I'm missing for my use case is batched inserts. I need to ingest millions of rows into a DB as quickly as possible, and non-batched inserts would be an issue. I know sqlx supports it, so I imagine it shouldn't be that difficult to implement. I could take a crack at it myself, if you're interested - although I am not very experienced with sqlx.

What do you think? Personally, it would mean I would never have to look at other ORMs again :)

Cheers, have a great day!

@RimaitosLab
Copy link

Hi,

I would also appreciate a feature like this.
For a current project I need to import a lot of data to sql databases for further processing.
As I didn't want to write long queries (hundreds of columns) and I already had the struct definition I though that ormx was a good fit. Sady I only noticed after the implementation that no batch insert is available and it takes ages to import the data, that I thing it is faster to replace ormx with sqlx than to wait for all inserts.

@NyxCode
Copy link
Owner

NyxCode commented Sep 18, 2024

Hey!

I have not yet found a nice way to reliably generate code for it, so I have not.
If what you end up with looks general enough to be includes in ormx, i'd definetely appreciate a PR.

that I thing it is faster to replace ormx with sqlx than to wait for all inserts.

that's the beauty of this setup, i think. You can still use ormx like before for everything else, and drop down to using sqlx for that specific query.

@NyxCode
Copy link
Owner

NyxCode commented Sep 18, 2024

As far as I can tell, the only nice way of doing batch inserts is on Postgres, by binding arrays and using UNNEST (docs). Some testing would need to be done to see if that works as-is for custom types, and if we can emit the correct SQL at all.

For example, it seems like the data needs to be "flat", every field in its own array. Not sure how to do that in the ormx API without being disgusting to use. We could accept a &[Table] and copy the fields over into temporary vectors, but that doesn't seem great either.

@belovaf
Copy link

belovaf commented Dec 7, 2024

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

No branches or pull requests

4 participants