square / sqlbrite

A lightweight wrapper around SQLiteOpenHelper which introduces reactive stream semantics to SQL operations.
https://square.github.io/sqlbrite/3.x/sqlbrite/
Apache License 2.0
4.57k stars 416 forks source link

Support for bulkInsert with BriteDatabase #225

Closed ShaishavGandhi closed 6 years ago

ShaishavGandhi commented 6 years ago

Something along the lines of db.bulkInsert(tableName = "posts", contentValues = posts) would be nice to have. I realize that BriteDatabase is a lightweight wrapper around SQLiteOpenHelper but it might be a useful API.

JakeWharton commented 6 years ago

While I understand the desire for such a thing, I don't want to get too into customizations at this layer beyond the APIs already provided by the wrapped API.

This currently isn't too hard to do with a transaction and a loop:

db.newTransaction().use {
  posts.forEach { db.insert("posts", it) }
}

We're likely going to move quite a bit of the functionality of this library into SQL Delight's runtime, and we won't have a way to offer bulk insertion at that layer. Because of these two facts, I'm going to resist adding something like this.

Also it looks like you are using Kotlin. I would encourage you to add such a thing as an extension function yourself for now.