Last active
December 7, 2022 03:34
-
-
Save oharaandrew314/24f32c19fc4ac4e9a11b9a58322bdb39 to your computer and use it in GitHub Desktop.
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
dependencies { | |
implementation("org.jetbrains.exposed:exposed-jdbc:0.40.1") | |
testImplementation("com.h2database:h2:2.1.214") | |
} |
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
import org.h2.jdbcx.JdbcDataSource | |
import org.jetbrains.exposed.sql.Database | |
import org.jetbrains.exposed.sql.SchemaUtils | |
import org.jetbrains.exposed.sql.transactions.transaction | |
import java.util.UUID | |
import javax.sql.DataSource | |
private fun testDb(): Database { | |
val dataSource: DataSource = JdbcDataSource().apply { | |
setURL("jdbc:h2:mem:${UUID.randomUUID()};MODE=MySQL;DB_CLOSE_DELAY=-1") | |
this.user = "sa" | |
this.password = "" | |
} | |
val db = Database.connect(dataSource) | |
transaction(db) { | |
SchemaUtils.create(CatsTable) | |
} | |
return db | |
} | |
class ExposedCatsRepoTest: CatsRepoContract(ExposedCatsRepo(testDb())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment