From d4c2e967ee885647d5dd7cc7e345d06008abcf74 Mon Sep 17 00:00:00 2001 From: Alex Pareto Date: Sun, 17 Jan 2021 11:45:39 -0800 Subject: [PATCH] Merge pull request #12 * add text field eagerLoading documentation --- DAO.md | 11 +++++++++++ Transactions.md | 19 +++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/DAO.md b/DAO.md index 939eb44..801a1ee 100644 --- a/DAO.md +++ b/DAO.md @@ -264,6 +264,17 @@ Similarly you can eager load references on Collections of DAO's such as Lists an StarWarsFilm.all().with(StarWarsFilm::actors) ``` NOTE: References that are eagerly loaded are stored inside the Transaction Cache, this means that they are not available in other transactions and thus must be loaded and referenced inside the same transaction. + +#### Eager loading for Text Fields +Some database drivers do not load text content immediately (for performance and memory reasons) which means that you can obtain the column value only within the open transaction. + +If you desire to make content available outside the transaction, you can use the eagerLoading param when defining the DB Table. +```kotlin +object StarWarsFilms : Table() { + ... + val description = text("name", eagerLoading=true) +} +``` ## Advanced CRUD operations ### Read entity with a join to another table Let's imagine that you want to find all users who rated second SW film with more than 5. diff --git a/Transactions.md b/Transactions.md index 87ff373..4edd997 100644 --- a/Transactions.md +++ b/Transactions.md @@ -18,11 +18,22 @@ val jamesList = transaction { } // jamesList is now a List containing Users data ``` -*Note:* `Blob` and `text` fields wont be available without transaction if you don't load them directly like: +*Note:* `Blob` and `text` fields won't be available outside of a transaction if you don't load them directly. For `text` fields you can also use the `eagerLoading` param when defining the Table to make the text fields available outside of the transaction. ```kotlin - val idsAndContent = transaction { - Documents.selectAll().limit(10).map { it[Documents.id] to it[Documents.content] } - } +// without eagerLoading +val idsAndContent = transaction { + Documents.selectAll().limit(10).map { it[Documents.id] to it[Documents.content] } +} + +// with eagerLoading for text fields +object Documents : Table() { + ... + val content = text("content", eagerLoading = true) +} + +val documentsWithContent = transaction { + Documents.selectAll().limit(10) +} ``` ### Working with a multiple databases