stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.59k stars 1.55k forks source link

implements batch insert rows, insertMany() #1048

Closed geoffmacd closed 2 years ago

geoffmacd commented 3 years ago

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

https://github.com/stephencelis/SQLite.swift/issues/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:

geoffmacd commented 3 years ago

tests pass locally, somethings not right with Travis CI though

nathanfallet commented 2 years ago

Fixes #897