https://kotlinlang.org logo
d

dany giguere

01/05/2022, 11:05 PM
Hello everyone. I’m in a Ktor project and I’m trying to install exposed. In which file am I supposed to put this :
Copy code
val config = HikariConfig().apply {
    jdbcUrl         = "jdbc:<mysql://localhost/dbname>"
    driverClassName = "com.mysql.cj.jdbc.Driver"
    username        = "username"
    password        = "secret"
    maximumPoolSize = 10
}
val dataSource = HikariDataSource(config)
Database.connect(dataSource)
from the documentation here: https://github.com/JetBrains/Exposed/wiki/DataBase-and-DataSource
e

Endre Deak

01/06/2022, 12:16 AM
I guess you can put it anywhere as long as this code is executed when the server starts.
d

dave08

01/06/2022, 4:04 AM
You can also put it in your DI to provide a Database instance for your repositories, especially if you have more than one database. Then you'd use
transaction(db) {}
3 Views