summaryrefslogtreecommitdiff
path: root/util/src/main/kotlin/DB.kt
diff options
context:
space:
mode:
authorMS <ms@taler.net>2023-06-14 12:03:34 +0200
committerMS <ms@taler.net>2023-06-14 12:03:34 +0200
commit1ddb0579cd9fd81a646e5138b2af453c7b978c9c (patch)
tree3238d9c1a0a8129326caad4a9097ece8170c86df /util/src/main/kotlin/DB.kt
parenta105222b827e8f607a7594226fb046fa68d17bad (diff)
downloadlibeufin-1ddb0579cd9fd81a646e5138b2af453c7b978c9c.tar.gz
libeufin-1ddb0579cd9fd81a646e5138b2af453c7b978c9c.tar.bz2
libeufin-1ddb0579cd9fd81a646e5138b2af453c7b978c9c.zip
Database versioning.
Getting to 'make check' to pass with the SQL files loaded from the filesystem.
Diffstat (limited to 'util/src/main/kotlin/DB.kt')
-rw-r--r--util/src/main/kotlin/DB.kt17
1 files changed, 17 insertions, 0 deletions
diff --git a/util/src/main/kotlin/DB.kt b/util/src/main/kotlin/DB.kt
index d8ac3fbe..b5147fa6 100644
--- a/util/src/main/kotlin/DB.kt
+++ b/util/src/main/kotlin/DB.kt
@@ -23,6 +23,7 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import logger
import net.taler.wallet.crypto.Base32Crockford
+import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.Transaction
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.transactions.transaction
@@ -229,4 +230,20 @@ fun getDatabaseName(): String {
}
}
return maybe_db_name ?: throw internalServerError("Could not find current DB name")
+}
+
+/**
+ * Abstracts over the Exposed details to connect
+ * to a database and ONLY use the passed schema
+ * WHEN PostgreSQL is the DBMS.
+ */
+fun connectWithSchema(dbConn: String, schemaName: String? = null) {
+ Database.connect(
+ dbConn,
+ user = getCurrentUser(),
+ setupConnection = { conn ->
+ if (isPostgres() && schemaName != null)
+ conn.schema = schemaName
+ }
+ )
} \ No newline at end of file