Alex Wood
01/20/2022, 7:53 PM[19:51:35 INFO]: [Nodes] [STDOUT] SQL: SELECT Users.id, Users.title, Users.town, Users.`role` FROM Users WHERE Users.id = '3e4bdaa7-33ae-3a69-a578-f43f78094268'
[19:51:35 INFO]: [Nodes] [STDOUT] SQL: SELECT Towns.id, Towns.`name`, Towns.nation_id, Towns.home_block_world, Towns.home_block_x, Towns.home_block_y, Towns.home_block_z, Towns.node_id FROM Towns WHERE Towns.id = '33d428d9-1b53-4b4b-bd74-c9583549a390'
Andreas Scheja
01/24/2022, 6:27 PMNayeem Zen
01/28/2022, 4:07 PMAdrian Devezin
02/01/2022, 5:11 PMCan't init value outside the transaction
, but its in a transaction. Has anyone encountered this before?
override suspend fun createUser(
name: String,
username: String,
bio: String,
igUsername: String?,
tiktokUsername: String?,
imageUrl: String,
imageWidth: Int,
imageHeight: Int
): User = dbQuery {
val avatar = Image.new(UUID.randomUUID()) {
url = imageUrl
height = imageHeight
width = imageWidth
}
val user = User.new(UUID.randomUUID()) {
this.name = name
this.username = username
this.bio = bio
this.igUsername = igUsername
this.tiktokUsername = tiktokUsername
this.avatar = avatar
}
return@dbQuery user
}
internal suspend fun <T> dbQuery(block: () -> T): T =
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
transaction {
if (System.getenv("environment").contentEquals("debug", ignoreCase = true)) {
addLogger(StdOutSqlLogger)
}
block()
}
}
Renaud
02/02/2022, 6:26 PMgiven_name
. Using Flyway, I’ve successfully added this new attribute to my table (I can see it using a DB file explorer) and I have added the following line :
object MyTable : ExtendedUUIDTable("whateverTable") {
...
val givenName: Column<String> = text("given_name")
}
When I try to use this field, I get the following exception :
java.lang.IllegalStateException: com.innovorder.server.data.model.WhateverTable.given_name is not initialized yet
I found that Exposed is missing some wiki pages regarding doing DB migration. Did someone run into this error as well?Jeanne De ArcRuler
02/03/2022, 2:04 AMDatabase.connect("jdbc:sqlite:/data/data.db", "org.sqlite.JDBC")
does the exposed automatically created the file for you?Damien
02/06/2022, 8:38 AMorder by my_json_column->'key' ASC
). Is it possible to write a raw/custom order expression for this? Not sure where to start.Calvin
02/07/2022, 1:52 PMEntity[id].apply {
updatedField = "test123"
}
But this is a bit tedious if the objects are very large and/or contain lists. Is there a method that detects the changes between two objects (the entity object and an updated version of the object) and updates the entity accordingly?Paul Higgins
02/07/2022, 9:29 PMDamien
02/08/2022, 3:43 PMGustav Elmgren
02/08/2022, 4:24 PMnullif
function). But I have no idea what to specify the column type as. Any thoughts?Paul Higgins
02/11/2022, 9:13 PMzt
02/16/2022, 2:52 AMGuild.update({ Guild.id eq guild.id.toString() }) {
it[data] = data + "abc"
}
For some reason, it always sets the value to "0"
The table is defined like this
object Guild : Table() {
val id = varchar("id", 18)
val data = text("data").default("")
override val primaryKey = PrimaryKey(id)
}
If I use it[data] = "whatever"
then it actually sets to the proper valueMrPowerGamerBR
02/17/2022, 10:09 PMupdate profiles set money = money * 0.95;
, money
is a bigint field on the table.
I tried doing this
Profiles.update {
with(SqlExpressionBuilder) {
it.update(Profiles.money, Profiles.money * 0.95)
}
}
However this doesn't work, because Profiles.money
is a Long, so PostgreSQL doesn't allow long + double multiplication :(zt
02/17/2022, 10:53 PM\n
but it just inserts the raw string instead of a newlineAgustin Magne
02/19/2022, 12:11 PMquery.orderBy(column)
This column is a string column, and I want the orderBy
statement NOT to be case sensitive. How can I achieve that? (without changing the column altogether to .lowercase()
Fred Bowker
02/25/2022, 1:19 PMrcd27
02/26/2022, 1:06 PMval innerJoin = ReceiptItems.join(Receipts, JoinType.INNER) { ReceiptItems.receiptId eq Receipts.id }
.join(Items, JoinType.INNER) { Receipts.resultItemId eq Items.id }
Is it possible to wrapRows
for a multiple entities, like ReceiptEntity.wrapRows(query)
, and others? I can extract all I need from a ResultSet
, but seems like iterating with next()
is a bit boilerplatyrcd27
02/28/2022, 10:24 AMexposed
lib is so cool. I love you, guys. (had an experience with JPA, fcking dark magic there)Paul Higgins
03/01/2022, 12:33 AMtransaction() {
try {
record.field = newValue
} catch (e: Exception) {
handleException()
}
doAThing()
}
Enrico Saggiorato
03/04/2022, 2:46 PMclass Users : IntIdTable() {
val username: Column<String> = varchar("username", 30)
val email: Column<String> = varchar("email", 255)
val password: Column<String> = varchar("password", 40)
}
now, if I try to invoke the functions of the Users class, Intellij gives no hints and screams about errors, for example I can't use Users.insertAndGetId
as stated in the docs. Am I missing something?Enrico Saggiorato
03/07/2022, 7:18 PMmaxmello
03/14/2022, 3:02 PMnewSuspendedTransaction { ... }
, and that’s it?
• have all your opening of transaction blocks in the DAO layer or “close” to the models, hidden from the point of view of the endpoint logic? The problem here is that sometimes when dealing with Entity instances, you pass it down to some application logic and then realize you actually need an active transaction to get access to the properties of the entity. Since I don’t want explicit control of transaction rollback etc. in most cases, it feels unnecessary to try to be very fine-grained with it. Some other libraries like Ebean won’t require the user to open transactions at all, except they want to change and rollback multiple entities at once.Leonid Yavorskyi
03/14/2022, 3:17 PMclass MyEntity(id: EntityID<UUID>) : UUIDEntity(id) {
companion object : UUIDEntityClass<MyEntity>(MyEntities)
var name by Migs.name
var unit by Migs.unit
val relations by MyRelationEntity referrersOn MyRelations.id
}
val myFieldIndex: Map<Expression<*>, Int> = mapOf(
MyEntities.id to 0,
MyEntities.name to 1,
MyEntities.unit to 2,
)
val myResultRowData = arrayOfNulls<Any?>(3)
myResultRowData[0]=1
myResultRowData[1]="Name1"
myResultRowData[2]="Unit1"
val e = MyEntity(EntityID(UUID.randomUUID(), Migs))
e._readValues = ResultRow(fieldIndex = myFieldIndex, data = myResultRowData)
// e.setRelations < --- how to set relations ???
Richard Romanowski
03/14/2022, 3:40 PMobject UserRatings: IntIdTable() {
val value = long("value")
val film = reference("film", StarWarsFilms)
val user = reference("user", Users)
}
class UserRating(id: EntityID<Int>): IntEntity(id) {
companion object : IntEntityClass<UserRating>(UserRatings)
var value by UserRatings.value
var film by StarWarsFilm referencedOn UserRatings.film // use referencedOn for normal references
var user by User referencedOn UserRatings.user
}
If I have the ID of a film how can I create a new rating with the DAO api?
Example:
val filmId: UUID = getFilmId()
val rating = UserRating.new {
// what goes here to set film?
}
Ayfri
03/20/2022, 7:17 PMUser
, Channel
, Message
etc classes, for a Compose Desktop project, but I now added a database and tables with what I was using, but when reading the documentation there's no way to transcript a select
to a class instance with similar fieldshawklike
03/21/2022, 4:01 PMprivate fun hikari(): HikariDataSource {
val config = HikariConfig()
config.driverClassName = "your db driver"
config.jdbcUrl = "your jdbcUrl"
config.maximumPoolSize = 3
config.isAutoCommit = false //1
config.transactionIsolation = "TRANSACTION_REPEATABLE_READ" //2
config.validate()
return HikariDataSource(config)
}
I see config.maximumPoolSize
often set to 3. I am not sure why it is specifically set to 3 but understand the idea (that is described in the Hikari Wiki page here).
On the other hand, what I really don't understand are commands config.isAutoCommit = false
(1) and config.transactionIsolation = "TRANSACTION_REPEATABLE_READ"
(2). Why are these two settings suggested when using Ktor with Exposed and not just sticking to default values?Nomantis Knight
03/23/2022, 10:25 PMclass ProjectRepositoryTest {
companion object {
val database = Database.connect("jdbc:sqlite:file:test?mode=memory&cache=shared", "org.sqlite.JDBC")
val projectRepository = ProjectRepository(database)
const val initialNumberOfProjects = 10
@BeforeAll
@JvmStatic
fun setUp() {
database.transactionManager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE
database.transactionManager.defaultRepetitionAttempts = 1
}
}
@BeforeEach
fun setUpEach() {
transaction(database) {
addLogger(StdOutSqlLogger)
SchemaUtils.create(ProjectsTable)
}
}
@Test
fun testGetAllProjects() {
println("Creating initial projects.")
transaction(database) {
addLogger(StdOutSqlLogger)
repeat(initialNumberOfProjects) { i ->
println("\tCreated project $i.")
ProjectEntity.new {
name = "Project $i"
description = "Description $i"
archived = 0b0
}
}
}
...
}
@AfterEach
fun tearDown() {
transaction(database) {
SchemaUtils.drop(ProjectsTable)
}
}
}
I'm getting a database does not exist exception, saying that the Projects table doesn't exist. What am I doing wrong?mitch
03/25/2022, 3:01 PMclientDefault
, are there any recommendations on what to do if I want updatedAt
to be set to the same datetime
as insertedAt
when we do a new()
?
https://github.com/JetBrains/Exposed/issues/342#issuecomment-540487409 gives a nice server-side answer, .defaultExpression(CurrentDateTime())
, but what if we want it client side so that the caller has the value set without committing the transaction?
I noticed that the `clientDefault`s are `invoke`d in the order the columns are registered. Is is acceptable to rely on that behavior? If so, I could do something like:
private data class ControlledUtc(var currentTime: LocalDateTime = utcNow()) {
fun getRefreshed(): LocalDateTime = utcNow().also { currentTime = it }
fun get(): LocalDateTime = currentTime
}
private val controlledUtc = ControlledUtc()
val insertedAt = datetime("inserted_at").clientDefault { controlledUtc.getRefreshed() }
var updatedAt = datetime("updated_at").clientDefault { controlledUtc.get() }
Thoughts? Other ideas?Allan Galarza
04/01/2022, 6:36 PMSELECT *,
CASE
WHEN reminder = 0 THEN start-$1::interval
WHEN reminder = 1 THEN start-$2::interval
WHEN reminder = 2 THEN start-$3::interval
WHEN reminder = 3 THEN start
END as notification
FROM "event"
WHERE start >= (now() + $4) AND active AND reminder <= 3
ORDER BY notification ASC LIMIT 1
The part I'm stuck with is subtracting from the Instant
type column start
, I'm looking for some kind of "interval literal" or something that I can use to add a Duration
in there.
val start = timestamp("start")
I have tried durationLiteral, but I'm still unsure on how to add it:
.When(EventTable.reminder eq 0, EventTable.start - (durationLiteral(1.hours.toJavaDuration())))
.When(EventTable.reminder eq 1, EventTable.start.minus(durationLiteral(1.hours.toJavaDuration())))