-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DatabaseConnection#inTransaction
- Loading branch information
1 parent
91731cc
commit 46f2af2
Showing
3 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
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
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
40 changes: 40 additions & 0 deletions
40
postgres/src/test/kotlin/tests/postgres/general/Transaction.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package tests.postgres.general | ||
|
||
import de.mineking.database.vendors.PostgresConnection | ||
import org.junit.jupiter.api.Test | ||
import setup.ConsoleSqlLogger | ||
import setup.UserDao | ||
import setup.recreate | ||
import kotlin.test.assertContentEquals | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
|
||
class TransactionTest { | ||
val connection = PostgresConnection("localhost:5432/test", user = "test", password = "test") | ||
val table = connection.getTable(name = "basic_test") { UserDao() } | ||
|
||
init { | ||
table.recreate() | ||
|
||
connection.driver.setSqlLogger(ConsoleSqlLogger) | ||
} | ||
|
||
@Test | ||
fun default() { | ||
connection.inTransaction { | ||
table.insert(UserDao(name = "Tom", email = "[email protected]", age = 12)) | ||
} | ||
|
||
assertEquals(1, table.selectRowCount()) | ||
} | ||
|
||
@Test | ||
fun rollback() { | ||
connection.inTransaction { | ||
table.insert(UserDao(name = "Tom", email = "[email protected]", age = 12)) | ||
it.rollback() | ||
} | ||
|
||
assertEquals(0, table.selectRowCount()) | ||
} | ||
} |