Skip to content

Commit

Permalink
docs: EXPOSED-578 Extend the Entity definition topic and add examples (
Browse files Browse the repository at this point in the history
…#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
vnikolova authored Nov 15, 2024
1 parent daaac26 commit e82ba9c
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 85 deletions.
3 changes: 1 addition & 2 deletions documentation-website/Writerside/hi.tree
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
</toc-element>
<toc-element toc-title="Deep Dive into DAO">
<toc-element topic="DAO-Table-Types.topic"/>
<toc-element topic="DAO-Entity-definition.topic"/>
<toc-element topic="DAO-Entity-definition.topic" accepts-web-file-names="dao-field-transformations.html"/>
<toc-element topic="DAO-CRUD-Operations.topic"/>
<toc-element topic="DAO-Relationships.topic"/>
<toc-element topic="DAO-Field-Transformations.topic"/>
</toc-element>
<toc-element toc-title="Releases">
<toc-element topic="Breaking-Changes.md"/>
Expand Down
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)
}
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ class UserEntity(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<UserEntity>(UsersTable)

var name by UsersTable.name
var city by CityEntity referencedOn UsersTable.cityId
}
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 documentation-website/Writerside/topics/DAO-Entity-definition.topic

Large diffs are not rendered by default.

This file was deleted.

1 change: 1 addition & 0 deletions documentation-website/Writerside/v.list
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<var name="product" value="Writerside"/>
<var name="exposed_version" value="0.56.0"/>
<var name="h2_db_version" value="2.2.224"/>
<var name="BASE_API_URL" value="https://jetbrains.github.io/Exposed/api"/>
</vars>

0 comments on commit e82ba9c

Please sign in to comment.