You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
csamsserver/src/MySQL.kt

28 lines
1005 B

package com.gyf.csams
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import io.ktor.application.*
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
fun Application.MySQL(testing: Boolean = false){
val config = HikariConfig().apply {
jdbcUrl = environment.config.property("ktor.deployment.mysql.jdbcUrl").getString()
driverClassName = environment.config.property("ktor.deployment.mysql.driverClassName").getString()
username = environment.config.property("ktor.deployment.mysql.username").getString()
password = environment.config.property("ktor.deployment.mysql.password").getString()
maximumPoolSize = 10
}
val dataSource = HikariDataSource(config)
Database.connect(dataSource)
initTable()
}
fun initTable(){
transaction {
SchemaUtils.createMissingTablesAndColumns(User)
}
}