-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExamplesDataSourceProvider.kt
49 lines (42 loc) · 1.34 KB
/
ExamplesDataSourceProvider.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package examples
import com.zaxxer.hikari.HikariDataSource
import kolbasa.AbstractPostgresqlTest
import org.testcontainers.containers.PostgreSQLContainer
import javax.sql.DataSource
object ExamplesDataSourceProvider {
/**
* Launch PostgreSQL in Docker container using TestContainers
*/
fun getDataSource(): DataSource {
val pgContainer = PostgreSQLContainer(AbstractPostgresqlTest.NEWEST_POSTGRES_IMAGE.dockerImage)
// Start PG container
pgContainer.start()
// Init dataSource
return HikariDataSource().apply {
jdbcUrl = pgContainer.jdbcUrl
username = pgContainer.username
password = pgContainer.password
}
}
/**
* Use external PostgreSQL installation
*
* If you want to use a real PG installation:
* 1) Comment out `getDataSource()` method above
* 2) Uncomment this one
* 3) Provide your own connection parameters (hostname, port, database, user, pwd)
*/
// fun getDataSource(): DataSource {
// val hostname = ""
// val port = 5432
// val database = ""
// val user = ""
// val pwd = ""
//
// return HikariDataSource().apply {
// jdbcUrl = "jdbc:postgresql://$hostname:$port/$database"
// username = user
// password = pwd
// }
// }
}