forked from DiscordBots/lilJudd
55 lines
1.9 KiB
Kotlin
55 lines
1.9 KiB
Kotlin
/*
|
|
* lilJudd
|
|
* Copyright (C) 2024 moonleay
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package net.moonleay.liljudd.data.database
|
|
|
|
|
|
import net.moonleay.liljudd.data.database.tables.MatchPlanningData
|
|
import net.moonleay.liljudd.data.database.tables.PlanningNotifierRoles
|
|
import net.moonleay.liljudd.data.database.tables.TimePlanningChannels
|
|
import net.moonleay.liljudd.data.database.tables.TimePlanningMessages
|
|
import org.jetbrains.exposed.sql.Database
|
|
import org.jetbrains.exposed.sql.SchemaUtils
|
|
import org.jetbrains.exposed.sql.transactions.transaction
|
|
|
|
object DB {
|
|
private var connected = false
|
|
|
|
//Connect to the provided DB; trows errors, if the DB is not available.
|
|
fun connect(dbDomain: String, dbName: String, dbUser: String, dbPasswd: String) {
|
|
Database.connect(
|
|
"jdbc:postgresql://$dbDomain/$dbName",
|
|
driver = "org.postgresql.Driver",
|
|
user = dbUser,
|
|
password = dbPasswd
|
|
)
|
|
connected = true
|
|
}
|
|
|
|
fun register() {
|
|
if (!connected)
|
|
return
|
|
// Register tables here
|
|
transaction {
|
|
SchemaUtils.create(TimePlanningChannels)
|
|
SchemaUtils.create(TimePlanningMessages)
|
|
SchemaUtils.create(MatchPlanningData)
|
|
SchemaUtils.create(PlanningNotifierRoles)
|
|
}
|
|
}
|
|
}
|