-
Notifications
You must be signed in to change notification settings - Fork 695
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: EXPOSED-578 Extend the Entity definition topic and add examples (…
…#2302) * docs: extend the Entity definition topic and add examples for method overrides and immutable entities * elaborate on props and methods for ImmutableEntityClass and fix code issues
- Loading branch information
Showing
8 changed files
with
275 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ebsite/Writerside/snippets/exposed-dao/src/main/kotlin/org/example/entities/CityEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.example.entities | ||
|
||
import org.example.tables.CitiesTable | ||
import org.jetbrains.exposed.dao.ImmutableEntityClass | ||
import org.jetbrains.exposed.dao.IntEntity | ||
import org.jetbrains.exposed.dao.id.EntityID | ||
|
||
class CityEntity(id: EntityID<Int>) : IntEntity(id) { | ||
val name by CitiesTable.name | ||
|
||
companion object : ImmutableEntityClass<Int, CityEntity>(CitiesTable) | ||
} |
16 changes: 16 additions & 0 deletions
16
...te/Writerside/snippets/exposed-dao/src/main/kotlin/org/example/entities/EntityWithUInt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.example.entities | ||
|
||
import org.jetbrains.exposed.dao.IntEntity | ||
import org.jetbrains.exposed.dao.IntEntityClass | ||
import org.jetbrains.exposed.dao.id.EntityID | ||
import org.jetbrains.exposed.dao.id.IntIdTable | ||
|
||
object TableWithUnsignedInteger : IntIdTable() { | ||
val uint = integer("uint") | ||
} | ||
|
||
class EntityWithUInt(id: EntityID<Int>) : IntEntity(id) { | ||
var uint: UInt by TableWithUnsignedInteger.uint.transform({ it.toInt() }, { it.toUInt() }) | ||
|
||
companion object : IntEntityClass<EntityWithUInt>(TableWithUnsignedInteger) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...rside/snippets/exposed-dao/src/main/kotlin/org/example/entities/UserEntityWithOverride.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.example.entities | ||
|
||
import org.example.tables.UsersTable | ||
import org.jetbrains.exposed.dao.IntEntity | ||
import org.jetbrains.exposed.dao.IntEntityClass | ||
import org.jetbrains.exposed.dao.id.EntityID | ||
|
||
class UserEntityWithOverride(id: EntityID<Int>) : IntEntity(id) { | ||
companion object : IntEntityClass<UserEntityWithOverride>(UsersTable) | ||
|
||
var name by UsersTable.name | ||
var city by CityEntity referencedOn UsersTable.cityId | ||
|
||
override fun delete() { | ||
println("Deleting user $name with ID: $id") | ||
super.delete() | ||
} | ||
} |
263 changes: 226 additions & 37 deletions
263
documentation-website/Writerside/topics/DAO-Entity-definition.topic
Large diffs are not rendered by default.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
documentation-website/Writerside/topics/DAO-Field-Transformations.topic
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters