maxmello
07/25/2022, 3:51 PMSchemaUtils.drop(ExampleTable); SchemaUtils.createMissingTablesAndColumns(ExampleTable)
, so recreating the table completely, I get the following log output:
17:02:26.029 [DefaultDispatcher-worker-1 @coroutine#3] DEBUG Exposed - DROP TABLE IF EXISTS example
17:02:26.066 [DefaultDispatcher-worker-1 @coroutine#3] INFO Exposed - Preparing create tables statements took 36ms
17:02:26.073 [DefaultDispatcher-worker-1 @coroutine#3] DEBUG Exposed - CREATE TABLE IF NOT EXISTS example (id BIGSERIAL PRIMARY KEY, "name" VARCHAR(64) NOT NULL, "isNamedAlice" BOOLEAN GENERATED ALWAYS AS ( example."name" = 'Alice' ) STORED NOT NULL)
17:02:26.084 [DefaultDispatcher-worker-1 @coroutine#3] INFO Exposed - Executing create tables statements took 17ms
17:02:26.097 [DefaultDispatcher-worker-1 @coroutine#3] INFO Exposed - Extracting table columns took 13ms
17:02:26.113 [DefaultDispatcher-worker-1 @coroutine#3] INFO Exposed - Extracting column constraints took 14ms
17:02:26.113 [DefaultDispatcher-worker-1 @coroutine#3] INFO Exposed - Preparing alter table statements took 29ms
17:02:26.124 [DefaultDispatcher-worker-1 @coroutine#3] DEBUG Exposed - ALTER TABLE example ALTER COLUMN "isNamedAlice" TYPE BOOLEAN GENERATED ALWAYS AS ( example."name" = 'Alice' ) STORED
17:02:26.127 [DefaultDispatcher-worker-1 @coroutine#3] WARN Exposed - Transaction attempt #1 failed: org.postgresql.util.PSQLException: ERROR: syntax error at or near "GENERATED"
As you can see, the table is originally created with the column “isNamedAlice” having NOT NULL, then immediately altered without that NOT NULL part. When looking into createMissingTablesAndColumns
, there seems to be a ColumnDiff triggered between the ColumnMetadata and Column. I could not find out which of the 4 comparisons triggered the change detection, but when looking into org.jetbrains.exposed.sql.vendors.PostgreSQL modifyColumn
, there only nullability and defaults are checked, and since both do not appear in the modify statement, I assume it is one of the other 2 (auto inc or case sensitive name).
Please look at the snippet for reference, even though I would say that an ALTER COLUMN statement should never trigger in this case.
In addition, the problem here is that GENERATED columns do not support ALTER COLUMN at all, only DROP/ADD column, resulting in the syntax error. There is currently no possibility to override modifyStatement from Column I think, but I guess the real problem remains that this modify statement is even executed with nothing actually modified.
(Postgres 14.4, Exposed 0.38.2, Kotlin 1.6.21, also tested with Exposed 0.37.3, 0.36.2)phldavies
07/26/2022, 11:06 AMvalue class Id(id: String)
I’d like to have a column Column<Id>
that wraps a varchar(12)
.Wyatt Kennedy
07/31/2022, 1:25 AMfun generateSchema(config: Config) {
val ds = PGSimpleDataSource()
ds.serverNames = arrayOf(config.host)
ds.databaseName = config.database
ds.user = config.username
ds.password = config.password
ds.currentSchema = config.schema
val actualDb = Database.connect(ds, databaseConfig = DatabaseConfig{
defaultSchema = Schema(config.schema)
})
transaction(actualDb) {
println(connection.schema)
SchemaUtils.setSchema(Schema(config.schema))
SchemaUtils.createMissingTablesAndColumns(*SCHEMA_LIST, withLogs = true)
}
}
Ovsyannikov Alexey
07/31/2022, 8:24 AMtapac
08/01/2022, 3:31 PMGustav Elmgren
08/03/2022, 3:01 PMinList
seems not to like the Expression<List<EntityId<>>>
in my case, and the thread was from three years ago...tapac
08/03/2022, 9:30 PMRobert Kempton
08/04/2022, 4:20 PMphldavies
08/08/2022, 11:21 AMignoreAndGetId
supposed to work differently for UUIDTable and IntTable?Filip Lastic
08/08/2022, 1:31 PMyou should not try to share a transaction between multiple threads as it will lead to undefined behaviour.
, but we have one usecase where we need to share transactions between threads. We have GraphQL DataLoaders https://opensource.expediagroup.com/graphql-kotlin/docs/server/data-loader/. DataLoader can be executed inside another thread and we have to call database query inside it.
We solved the issue by using nested transactions and using wrapper on our code:
TransactionManager.manager.bindTransactionToThread(outerTx)
return synchronized(outerTx) {
transaction {
TransactionManager.manager.bindTransactionToThread(this)
statement()
}
}
Do you think this this is a totally anti-pattern and we should do this in some other way or it is an acceptable solution?Gustav Elmgren
08/09/2022, 1:59 PMFlights
.join(...)
.join(...)
And then I have an optional join
based on another parameter. One solution I guess is to use a var:
var joins = Flights
.join(...)
.join(...)
if (condition) { joins = joins.join(AnotherTable...) }
Is there any feature in kotlin that make it possible to do the if in the assignment so I can keep it as a val
? (or something like adjustWhere
in Exposed)
Flights
.join(...)
.join(...)
.someMagicKotlinMethod {
if (condition) ...
}
Muhammad Talha
08/17/2022, 5:00 AMptmt
08/22/2022, 9:44 AMoverride fun afterExecution(
transaction: Transaction,
contexts: List<StatementContext>,
executedStatement: PreparedStatementApi,
) {
}
hhariri
08/23/2022, 12:51 PMGustav Elmgren
08/26/2022, 8:30 AMfun distanceInKm(lat1: Column<Double>, long1: Column<Double>, lat2: Column<Double>, long2: Column<Double>) =
Expression.build {
ACos(
Sin(
(doubleLiteral(PI) * lat1 / doubleLiteral(180.0))
) *
Sin(doubleLiteral(PI) * lat2 / doubleLiteral(180.0))
+
Cos(doubleLiteral(PI) * lat1 / doubleLiteral(180.0)) *
Cos(doubleLiteral(PI) * lat2 / doubleLiteral(180.0)) *
Cos(doubleLiteral(PI) * (long1 - long2) / doubleLiteral(180.0))
).times(
doubleLiteral(180.0) / doubleLiteral(PI) * doubleLiteral(60.0) * doubleLiteral(1.1515) * doubleLiteral(
1.609344
)
)
}
But I just realized that two of the columns are nullable (lat2
, long2
), which breaks the method. Is there anything like !!
in exposed? Given I know the values are not null because of my where
.zt
08/30/2022, 4:04 AMobject Guilds : IntIdTable() {
val markovConfig = reference("markov_config", MarkovConfigs)
}
class Guild(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<Guild>(Guilds)
var markovConfig by MarkovConfig referencedOn Guilds.markovConfig
}
object MarkovConfigs : IntIdTable() {
val frequency = float("frequency")
val handleMention = bool("handle_mention").default(true)
}
class MarkovConfig(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<MarkovConfig>(MarkovConfigs)
var frequency by MarkovConfigs.frequency
var handleMention by MarkovConfigs.handleMention
}
Gustav Elmgren
08/30/2022, 3:09 PMtimestamp
type in exposed. I have a postgres db with with a table that has a timestamp
column. And the timestamp
in exposed is of JavaInstantColumnType
. Both instant and the column type in postgres does not have a concept of timezones. So why is the system timezone applied when I fetch the column via exposed? Is this possible to prevent?Bartłomiej Kozak
09/02/2022, 5:51 PMsuspend fun <T> dbQuery(block: suspend () -> T): T = newSuspendedTransaction(<http://Dispatchers.IO|Dispatchers.IO>) { block() }
override suspend fun isEmailTaken(email: String): Boolean = dbQuery {
UserEntity.find {
UsersTable.email eq email
}.firstOrNull()
} == null
and
override suspend fun isEmailTaken(email: String): Boolean = dbQuery {
UserEntity.find {
UsersTable.email eq email
}.firstOrNull() == null
}
?
Should I check if the value exists in the another way?Hachemi Hamadi
09/03/2022, 11:20 AMobject OperatorsTable : IdTable<String>("operators") {
override val id: Column<EntityID<String>> = varchar(name = "id", length = 14).entityId().uniqueIndex()
val name = varchar("name", length = 50)
......
}
class OperatorEntity(id: EntityID<String>) : StringEntity(id) {
companion object : StringEntityClass<OperatorEntity>(OperatorsTable)
var name by OperatorsTable.name
....
}
// Get all
val usersList = transaction {
OperatorEntity.all().toList()
}
I get this error:
java.lang.IllegalStateException: Resource not found in classpath: kotlin/kotlin.kotlin_builtins
Exposed Version: 0.39.2
PostgresDriver: 42.5.0
Kotlin: 1.7.10
Any idea why this is happening ?Pratik Tandel
09/13/2022, 2:08 AMStuart Baker
09/15/2022, 6:17 PMTheOnlyTails
09/17/2022, 6:13 PMorg.postgresql.util.PSQLException: Something unusual has occurred to cause the driver to fail. Please report this exception.
here is the full log: https://gist.github.com/TheOnlyTails/a5e901beef65f023973c8b22136a8823Sergei
09/19/2022, 12:06 PMzt
10/03/2022, 10:56 PMtransaction {
Filter.new {
guild = Guild.findById(guildId)!!
pattern = arguments.filter.toString()
action = FilterAction.REPLY
response = arguments.content
}
}
Is there some simpler way of doing this? like instead I would fetch the Guild database object and then insert into its filters columnSuser
10/04/2022, 6:59 AMAdam Cooper
10/04/2022, 7:36 PMtapac
10/05/2022, 1:45 PMBerkay Özkan
10/06/2022, 1:12 PMobject Users: IntIdTable() {
val name = varchar("name", 50)
}
class User(id: EntityID<Int>): IntEntity(id) {
companion object : IntEntityClass<User>(Users)
var name by Users.name
}
object UserRatings: IntIdTable() {
val value = long("value")
val user = reference("user", Users)
}
class UserRating(id: EntityID<Int>): IntEntity(id) {
companion object : IntEntityClass<UserRating>(UserRatings)
var value by UserRatings.value
var user by User referencedOn UserRatings.user
}
When i want to create new UserRating i get id of user, and value (5 star etc)
val movie = UserRating.new {
value = 5
user = ? // This expects an User object
}
How can I use only id when creating UserRating? Or do i have to get User from db with selectById? (Isn’t it unneccesarry get operation?)Jackie Whittle
10/07/2022, 2:56 PMGustav Elmgren
10/18/2022, 2:06 PM.with(Entity::relation
, but when said relation is accessed, outside of the transaction it was fetched from, I get Can't init value outside the transaction
. My understanding was that using With
would load all relations eagerly, is that wrong?Gustav Elmgren
10/18/2022, 2:06 PM.with(Entity::relation
, but when said relation is accessed, outside of the transaction it was fetched from, I get Can't init value outside the transaction
. My understanding was that using With
would load all relations eagerly, is that wrong?Leonid Yavorskyi
10/18/2022, 7:26 PMNOTE: 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.
Gustav Elmgren
10/18/2022, 7:27 PM