Merge pull request #12

* add text field eagerLoading documentation
This commit is contained in:
Alex Pareto
2021-01-17 11:45:39 -08:00
committed by GitHub
parent be77f8ef0e
commit d4c2e967ee
2 changed files with 26 additions and 4 deletions

11
DAO.md
View File

@@ -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.

View File

@@ -18,11 +18,22 @@ val jamesList = transaction {
}
// jamesList is now a List<ResultRow> 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