Last active
March 19, 2020 08:39
-
-
Save jlengrand/9f1e9f9294dbe96442908189fa1c226e to your computer and use it in GitHub Desktop.
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