Created
July 19, 2020 10:28
-
-
Save hkakutalua/186ada5c263747909736e3dc892fe8bf to your computer and use it in GitHub Desktop.
PostgresDbCleanerExtension cleanTablesData
This file contains hidden or 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
@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