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

implements batch insert rows, insertMany() #1048

Merged
merged 12 commits into from
Aug 21, 2021

Conversation

geoffmacd
Copy link
Contributor

@geoffmacd geoffmacd commented Apr 30, 2021

Feature improvement: ability to insert multiple rows in one statement.

#168

This is something I personally need at dropbox for performance as its more efficient to bind to a single statement rather than recreating many similar INSERT Statements. In my use case, using this improves performance for 1 column string insert from ~0.34 seconds for 10,000 rows in a transaction to ~0.08s for 10,000 rows which is inline (to order of magnitude) with other sqlite benchmarks across the internet like https://medium.com/@JasonWyatt/squeezing-performance-from-sqlite-insertions-971aff98eef2.

Supports all the variations I could see including Encodables and the various syntaxes. There is a slight concern which is that this depends on at least 1 object to find the columns, otherwise, we have to default to some return that makes the API easy to use. eg. it should not return an Insert?. Suggestions welcome here. Added tests as well.

Example usage:

  • insert many with 1 column: users.insertMany([mail <- "alice@mac.com"], [email <- "geoff@mac.com"])

@geoffmacd
Copy link
Contributor Author

tests pass locally, somethings not right with Travis CI though

geoffmacd pushed a commit to geoffmacd/SQLite.swift that referenced this pull request May 3, 2021
@nathanfallet
Copy link
Collaborator

Fixes #897

@nathanfallet nathanfallet linked an issue Aug 21, 2021 that may be closed by this pull request
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.

How to insert multiple record at once
2 participants