Joshua Hansen
01/22/2024, 11:27 PMLinus
01/23/2024, 4:22 PMtransaction {
Table.update({ Table.id eq targetId }) {
it[someField] = if (request.someField != null) { request.someField } else { it[someField] }
}
}
How can I do something like this?oSumAtrIX
01/30/2024, 3:36 PMobject AnnouncementsTable : IntIdTable() {
val author = varchar("author", 32).nullable()
val title = varchar("title", 64)
val content = text("content").nullable()
val channel = varchar("channel", 16).nullable()
val createdAt = datetime("createdAt")
val archivedAt = datetime("archivedAt").nullable()
val level = integer("level")
}
object AttachmentsTable : IntIdTable() {
val url = varchar("url", 256)
}
So I am trying to make a many to one relation between attachments and announcements. Each announcement can have multiple attachments, but I am not sure how to proceed here. The Exposed wiki is unclear to me hereoSumAtrIX
01/30/2024, 3:37 PMclass Announcement(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<Announcement>(AnnouncementsTable)
var author by AnnouncementsTable.author
var title by AnnouncementsTable.title
var content by AnnouncementsTable.content
var attachmentUrls by Attachment via AttachmentsTable
var channel by AnnouncementsTable.channel
var createdAt by AnnouncementsTable.createdAt
var archivedAt by AnnouncementsTable.archivedAt
var level by AnnouncementsTable.level
}
class Attachment(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<Attachment>(AttachmentsTable)
var url by AttachmentsTable.url
}
These are the entities I have now, but I get the exception, table does not reference sourceJoshua Hansen
01/30/2024, 9:15 PMjava.lang.IllegalArgumentException: Can't finish initialization for entity MyClassName - the initialization order is broken
Alexander
01/31/2024, 9:45 AMOp<Boolean>
? My issue is that I want to do Time(MyTable.timestamp).between(startTime, endTime)
, but the TIME
expression isn't available in Postgres. The way to do it in postgres would be with table_name.timestamp::time BETWEEN startTime AND endTime
So I would like to do something like:
MyTable.select(MyTable.columns)
.where { literalExpression("my_table.timestamp::time between $startTime AND $endTime") }
Jocelyne Abi Haidar
01/31/2024, 11:55 AMManas Marthi
02/02/2024, 9:47 PMsuspend fun insertIntoTwoTables(x: Int, y: Int) {
Database.dbQuery{
transaction{
var a = Numbers.insert { it[Numbers.num] = x }
val aId = a.resultedValues?.get(Numbers.id) ?.let { it.toLong() }
val b = Strings.insert {
it[Strings.str] = y.toString()
it[Strings.numId] = aId
}
val bId = b.resultedValues?.get(Strings.id) ?.let { it.toLong() }
return Pair(aId, bId)
}
}
}
Axel
02/07/2024, 9:31 PMManas Marthi
02/11/2024, 6:30 PMsuspend fun <T> dbQuery(block: suspend () -> T): T =
newSuspendedTransaction(<http://Dispatchers.IO|Dispatchers.IO>) { block() }
Manasseh
02/15/2024, 6:48 PMval db = Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver")
MerlinTHS
02/19/2024, 9:46 AMHildebrandt Tobias
02/20/2024, 1:21 PMye olden code
is there no better
way to do this in exposed?
fun upsertTelegramFilter(filter: IbisTelegramFilterDTO) = transaction {
val exists = TelegramFilterTable
.select { TelegramFilterTable.id eq filter.id }
.singleOrNull() != null
if(exists)
TelegramFilterTable.update {
it[this.companyId] = filter.companyId
it[this.name] = filter.name
it[this.type] = filter.type
it[this.text] = filter.text
}
else
TelegramFilterTable.insert {
it[this.companyId] = filter.companyId
it[this.name] = filter.name
it[this.type] = filter.type
it[this.text] = filter.text
}
}
Emirhan Emmez
02/20/2024, 1:27 PMencryptedvarchar
? There would be a great if there is an example on github.Lubomir Pisk
02/20/2024, 6:43 PMjdbc:oracle:thin:@aldjjdafas23a_high?TNS_ADMIN=/Users/username/Wallet_ZJHD234J53H3762
martmists
02/21/2024, 7:42 AMDominik Sandjaja
02/21/2024, 1:51 PM.upsert(){}
) functionality in exposed, is there a way to exclude a column from being updated when an update is done? Or is the only way to do so by defining a dedicated onUpdate
statement? I was hoping of something like onUpdateExclude: Array<Column<*>>
.
My usecase: I have tables with a column like
val createdAt = datetime("created_at").defaultExpression(CurrentDateTime)
which works fine for inserts, but I clearly don't want to update this column when I UPDATE
the column.Rafał Kuźmiński
02/21/2024, 2:41 PMPablichjenkov
02/24/2024, 10:01 PMGreg Poirier
02/27/2024, 9:52 PMeq
operator when comparing two columns one of Column<String> with Column<EntityID<String>>. I've got a way around this, but I'm wondering if there is a cleaner way. More detail in 🧵Chantal Loncle
02/28/2024, 12:33 PMSašo
03/01/2024, 4:24 PMnewSuspendedTransaction
and withSuspendTransaction
, with comments explaining that the blocks will be run separately in "some thread from the dispatcher" (unclear if this is the same thread or multiple threads from same dispatcher) but both reusing the same transaction. However, just a couple of lines lower, there is a warning about not sharing a transaction between multiple threads. I am not sure if the example is doing just that (sharing a transaction between multiple threads), but regardless of that, I'm curious what the example would look like if there was a suspending function added to the mix, that also needs to reuse the same transaction.
In order to not do https://xyproblem.info/ , I am trying to implement a standard queue using a postgres table, basically a SELECT * FROM queue WHERE somecolumn IS NULL FOR UPDATE SKIP LOCKED
-> do some work that might or might not include suspending functions and will also need to do additional database queries, so I definitely want to reuse the existing transaction/connection -> set somecolumn
to the finish time.
Appreciate any help or pointers to examples!Fernando Sanchez (Perraco Labs)
03/01/2024, 7:29 PMBastien Leveque
03/03/2024, 7:42 PM2024-03-03 18:04:50 java.lang.reflect.InvocationTargetException
2024-03-03 18:04:50 at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
2024-03-03 18:04:50 at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
2024-03-03 18:04:50 at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
2024-03-03 18:04:50 at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
2024-03-03 18:04:50 at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
2024-03-03 18:04:50 at kotlin.reflect.jvm.internal.calls.CallerImpl$Constructor.call(CallerImpl.kt:41)
2024-03-03 18:04:50 at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:107)
2024-03-03 18:04:50 at org.jetbrains.exposed.dao.EntityClass$entityCtor$1.invoke(EntityClass.kt:32)
2024-03-03 18:04:50 at org.jetbrains.exposed.dao.EntityClass$entityCtor$1.invoke(EntityClass.kt:32)
2024-03-03 18:04:50 at org.jetbrains.exposed.dao.EntityClass.createInstance(EntityClass.kt:229)
2024-03-03 18:04:50 at org.jetbrains.exposed.dao.EntityClass.new(EntityClass.kt:264)
2024-03-03 18:04:50 at org.jetbrains.exposed.dao.EntityClass.new(EntityClass.kt:247)
2024-03-03 18:04:50 at fr.ftnl.economy.database.models.BankAccount2$Companion.create$lambda$1(BankAccountTable2.kt:29)
2024-03-03 18:04:50 at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction$run(ThreadLocalTransactionManager.kt:215)
2024-03-03 18:04:50 at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.access$inTopLevelTransaction$run(ThreadLocalTransactionManager.kt:1)
2024-03-03 18:04:50 at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$inTopLevelTransaction$1.invoke(ThreadLocalTransactionManager.kt:241)
2024-03-03 18:04:50 at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:249)
2024-03-03 18:04:50 at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:240)
2024-03-03 18:04:50 at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$transaction$1.invoke(ThreadLocalTransactionManager.kt:190)
2024-03-03 18:04:50 at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:249)
2024-03-03 18:04:50 at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:160)
2024-03-03 18:04:50 at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:146)
2024-03-03 18:04:50 at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction$default(ThreadLocalTransactionManager.kt:145)
2024-03-03 18:04:50 at fr.ftnl.economy.database.models.BankAccount2$Companion.create(BankAccountTable2.kt:28)
2024-03-03 18:04:50 at fr.ftnl.economy.bot.commands.modules.Balance.action(Balance.kt:26)
2024-03-03 18:04:50 at fr.ftnl.economy.bot.commands.InteractionCommandHandler.dispatch(InteractionCommandHandler.kt:72)
2024-03-03 18:04:50 at fr.ftnl.economy.bot.commands.InteractionCommandHandler$dispatch$1.invokeSuspend(InteractionCommandHandler.kt)
2024-03-03 18:04:50 at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2024-03-03 18:04:50 at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:270)
2024-03-03 18:04:50 at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
2024-03-03 18:04:50 at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
2024-03-03 18:04:50 at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
2024-03-03 18:04:50 at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
2024-03-03 18:04:50 at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
2024-03-03 18:04:50 at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
2024-03-03 18:04:50 at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2024-03-03 18:04:50 Caused by: java.lang.IllegalStateException: Column and factory point to different tables
2024-03-03 18:04:50 at org.jetbrains.exposed.dao.Referrers.<init>(References.kt:62)
2024-03-03 18:04:50 at org.jetbrains.exposed.dao.EntityClass.referrersOn(EntityClass.kt:324)
2024-03-03 18:04:50 at fr.ftnl.economy.database.models.BankAccount2.<init>(BankAccountTable2.kt:51)
2024-03-03 18:04:50 ... 36 more
thank you in advance for your helpdavid dereba
03/06/2024, 5:59 AMjava.sql.SQLSyntaxErrorException: User 'cashio' has exceeded the 'max_questions' resource (current value: 1000)
reactormonk
03/08/2024, 3:35 PMDeepak Gahlot
03/09/2024, 7:17 AMFernando Sanchez (Perraco Labs)
03/09/2024, 12:03 PM@CreationTimestamp
and @UpdateTimestamp
annotations, to automatically handle the creation and update timestamps for entity fields?Jeffrey Kwok
03/14/2024, 7:11 PMStartWarsFilmActors
and in the dao class like:
class StarWarsFilm(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<StarWarsFilm>(StarWarsFilms)
...
var actors by Actor via StarWarsFilmActors
var extraDataFromJunctionTable // ?
...
}
Tyler Kinkade
03/16/2024, 9:34 AM