Skip to content

Instantly share code, notes, and snippets.

@jlengrand
Last active March 19, 2020 08:39
Show Gist options
  • Save jlengrand/9f1e9f9294dbe96442908189fa1c226e to your computer and use it in GitHub Desktop.
Save jlengrand/9f1e9f9294dbe96442908189fa1c226e to your computer and use it in GitHub Desktop.
Transcations split in Exposed
private fun loadData(db : Database, table: Table, fileName: String, partitions: Int, operation: BatchInsertStatement.(String) -> Unit){
val reader = File(fileName).bufferedReader()
reader.readLine() // pass headers
val lines = reader.readLines()
val partitionSize = lines.size / partitions
val listOfLists = lines.chunked(partitionSize)
var increment = 0
for(listOfList in listOfLists){
increment += 1
println("-------- $increment")
transaction(db) {
table.batchInsert(listOfList, body = operation)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment