Transcations split in Exposed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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