https://kotlinlang.org logo
#exposed
Title
# exposed
g

Giuliopime

11/10/2023, 11:38 AM
Have a couple of questions regarding transactions: • it's still mandatory to use the
transaction
block even when using DAOs correct? • when working with ktor, I saw that the sample uses the
newSuspendedTransaction
function. Is this necessary because ktor uses coroutines, or is it optional? • If I declare the database connection in a class, can I then use the
transaction
block without passing the db as a parameter, is it handled by exposed already?
Additionally, let's say I wanna create a function that maps my externally visible data classes to entity classes. Is there a way I can specify the id too in that mapping function, without having to declare the id myself in the table and keep using
UUIDTable
instead? Example
Copy code
private fun UserEntity.fromDto(userDto: UserDto) {
        email = userDto.email
        passwordHash = userDto.passwordHash
        emailVerified = userDto.emailVerified
        createdAt = userDto.creationTimestamp
        creationSource = userDto.creationSource
}

UserEntity.new(userDto.id.id) {
  fromDto(userDto)
}
Another question, is there any documentation for
notForUpdate
?
a

Aleksei Tirman [JB]

11/15/2023, 4:25 PM
• Yes, otherwise the
java.lang.IllegalStateException: No transaction in context.
will be thrown. • It's optional but better for the user experience. • You can. In that case the last connection will be used.
2 Views