Skip to content

Instantly share code, notes, and snippets.

@hkakutalua
Created July 19, 2020 10:28
Show Gist options
  • Save hkakutalua/186ada5c263747909736e3dc892fe8bf to your computer and use it in GitHub Desktop.
Save hkakutalua/186ada5c263747909736e3dc892fe8bf to your computer and use it in GitHub Desktop.
PostgresDbCleanerExtension cleanTablesData
@Throws(SQLException::class)
private fun cleanTablesData(tablesNames: List<TableData>, connection: Connection) {
if (tablesNames.isEmpty()) {
return
}
val stringBuilder = StringBuilder("TRUNCATE ")
for (i in tablesNames.indices) {
if (i == 0) {
stringBuilder.append(tablesNames[i].fullyQualifiedTableName)
} else {
stringBuilder
.append(", ")
.append(tablesNames[i].fullyQualifiedTableName)
}
}
connection.prepareStatement(stringBuilder.toString())
.execute()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment