Skip to content

Instantly share code, notes, and snippets.

@oharaandrew314
Last active December 7, 2022 03:34
Show Gist options
  • Save oharaandrew314/24f32c19fc4ac4e9a11b9a58322bdb39 to your computer and use it in GitHub Desktop.
Save oharaandrew314/24f32c19fc4ac4e9a11b9a58322bdb39 to your computer and use it in GitHub Desktop.
dependencies {
implementation("org.jetbrains.exposed:exposed-jdbc:0.40.1")
testImplementation("com.h2database:h2:2.1.214")
}
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