From 79c708b64538c3bbe490fcb782ab14f37861a8e2 Mon Sep 17 00:00:00 2001 From: Joel Feinstein Date: Sun, 17 Jan 2021 14:46:50 -0500 Subject: [PATCH] Document default database behavior (#13) * Document default database behavior --- Transactions.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Transactions.md b/Transactions.md index 4edd997..5e9b459 100644 --- a/Transactions.md +++ b/Transactions.md @@ -39,7 +39,7 @@ val documentsWithContent = transaction { ### Working with a multiple databases _This functionality supported since 0.10.1 version_ -When you want to work with different databases then you have to store database reference returned by `Database.connect()` and provide it to `transaction` function as first parameter. As before 0.10.1, `transaction` block without parameters will work with the latest _connected_ database. +When you want to work with different databases then you have to store database reference returned by `Database.connect()` and provide it to `transaction` function as first parameter. ```kotlin val db1 = connect("jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;", "org.h2.Driver", "root", "") val db2 = connect("jdbc:h2:mem:db2;DB_CLOSE_DELAY=-1;", "org.h2.Driver", "root", "") @@ -55,6 +55,15 @@ transaction(db1) { Entities (see [[DAO API|DAO]] page) `stick` to a transaction that was used to load that entity. That means that all changes persist to the same database and what cross-database references are prohibited and will throw exceptions. +### Setting default database +`transaction` block without parameters will use the default database. +As before 0.10.1 this will be the latest _connected_ database. +It is also possible to set the default database explicitly. +```kotlin +val db = Database.connect() +TransactionManager.defaultDatabase = db +``` + ### Using nested transactions Since Exposed 0.16.1 it is possible to use nested transactions. To enable this feature you should set `useNestedTransactions` on desire `Database` instance to `true`.