make everything Customisable™️

This commit is contained in:
Ecorous 2024-06-08 15:05:58 +01:00
parent 48b5ea3c04
commit 89b8a9c132
Signed by: Ecorous
SSH key fingerprint: SHA256:ni7WK6Ud51dVmDv8DctoqLEr3XXhAI51s6IFMYvJKDM

View file

@ -7,15 +7,25 @@ import org.jetbrains.exposed.sql.transactions.transaction
object DB { object DB {
var db: Database? = null var db: Database? = null
private fun getEnv(name: String, default: String): String {
return System.getenv(name) ?: default
}
fun init(): Boolean { fun init(): Boolean {
// use postgresql // use postgresql
try { try {
val database = getEnv("FROGMC_META_DATABASE", "frogmc")
val user = getEnv("FROGMC_META_USER", "postgres")
val password = getEnv("FROGMC_META_PASSWORD", "example")
val host = getEnv("FROGMC_META_HOST", "localhost")
val port = getEnv("FROGMC_META_PORT", "5432")
logger.info("Connecting to the database...") logger.info("Connecting to the database...")
val d = Database.connect( val d = Database.connect(
url = "jdbc:postgresql://localhost:5432/frogmc", url = "jdbc:postgresql://$host:$port/$database",
driver = "org.postgresql.Driver", driver = "org.postgresql.Driver",
user = "postgres", user,
password = "example" password
) )
db = d db = d
transaction(db) { transaction(db) {