feat: dbのurlなどを指定できるように

This commit is contained in:
usbharu 2023-03-24 22:54:19 +09:00
parent 4e613c4590
commit 62eb6ddcce
3 changed files with 11 additions and 6 deletions

View File

@ -25,8 +25,7 @@ import org.jetbrains.exposed.sql.Database
import org.koin.ktor.ext.inject import org.koin.ktor.ext.inject
import java.util.* import java.util.*
fun main(args: Array<String>): Unit = fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
io.ktor.server.netty.EngineMain.main(args)
@Suppress("unused") // application.conf references the main function. This annotation prevents the IDE from marking it as unused. @Suppress("unused") // application.conf references the main function. This annotation prevents the IDE from marking it as unused.
fun Application.module() { fun Application.module() {
@ -34,8 +33,8 @@ fun Application.module() {
single<Database> { single<Database> {
Database.connect( Database.connect(
url = "jdbc:h2:./test;MODE=POSTGRESQL", url = environment.config.property("hideout.database.url").getString(),
driver = "org.h2.Driver", driver = environment.config.property("hideout.database.driver").getString(),
) )
} }
single<ConfigData> { single<ConfigData> {

View File

@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
object Config { object Config {
var configData:ConfigData = ConfigData("", jacksonObjectMapper()) var configData: ConfigData = ConfigData()
} }
data class ConfigData(val hostname:String,val objectMapper: ObjectMapper) data class ConfigData(val hostname: String = "", val objectMapper: ObjectMapper = jacksonObjectMapper())

View File

@ -13,4 +13,10 @@ ktor {
hideout { hideout {
hostname = "https://localhost:8080" hostname = "https://localhost:8080"
hostname = ${?HOSTNAME} hostname = ${?HOSTNAME}
database {
url = "jdbc:h2:./test;MODE=POSTGRESQL"
driver = "org.h2.Driver"
username = ""
password = ""
}
} }