Nick Halase
04/04/2022, 9:04 PMorg.hibernate.context.spi.CurrentTenantIdentifierResolver
and org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
to set the database schema using SecurityContextHolder.getContext()
to determine the schema
• The Ktor service is attempting to do the same schema-based tenant isolation, but instead is doing this with `Exposed`:
import org.jetbrains.exposed.sql.Table
fun getDynamicSchemaName(): String {
TODO("How can I get access to the request-scoped JWTPrincipal to determine this?")
}
open class SchemaTable(private val name: String) : Table() {
override val tableName: String
get() = "${getDynamicSchemaName()}.$name"
}
Here is an example `Route`:
@ExperimentalCoroutinesApi
fun Route.fooFindAllRoute(fooService: FooService) {
authenticate("auth0") {
get("/foo") {
val principal = call.principal<JWTPrincipal>() ?: error("missing JWTPrincipal on authenticated request")
call.respond(fooService.findAll(principal).map { it.toResource() })
}
}
}
I don't like this because it poops up my service API by requiring the principal
.
---
Is there a better way to do what I'm trying to do here with Ktor and Exposed?ron
04/07/2022, 11:15 AMMartin Gaens
04/11/2022, 10:36 PMContentNegotiation
plugin to deserialize and edit an entry in the database.alon shoshani.86
04/13/2022, 11:33 AMUPDATE events_affecting_transit
SET estimated_affect_end_time = estimated_affect_end_time + interval '5 hour'
WHERE current_timestamp > estimated_affect_end_time
Ron S
04/27/2022, 8:45 AMclass UserEntity(id: EntityID<Long>) : LongEntity(id) {
companion object : LongEntityClass<UserEntity>(UserTable)
var username by UserTable.username
}
class TestEntity(id: EntityID<Long>) : LongEntity(id) {
companion object : LongEntityClass<TestEntity>(TestTable)
var author by UserEntity referencedOn TestTable.autor
// var author by TestTable.author // not this way
}
transaction {
TestEntity.all().first().author // triggers fetch of entire entity
TestEntity.all().first().readValues[TestTable.author] // returns the desired id but is a little awkward
}
I want to benefit from the dao api by fetching entire related entites (like author here).
However, there are some use cases when the id of the referenced entity is sufficient and I don't want to cause another database query to fetch the other unneeded columns.
The only - but awkward - way I found to achieve this was by using "readValues". Is there any better solution that I have overlooked?Brian Estrada
05/05/2022, 3:07 PMalbrechtroehm
05/09/2022, 3:35 PM"level":"WARN","stack_trace":"org.postgresql.util.PSQLException: Cannot change transaction isolation level in the middle of a transaction.\n\tat org.postgresql.jdbc.PgConnection.setTransactionIsolation(PgConnection.java:946)\n\tat com.zaxxer.hikari.pool.ProxyConnection.setTransactionIsolation(ProxyConnection.java:420)\n\tat com.zaxxer.hikari.pool.HikariProxyConnection.setTransactionIsolation(HikariProxyConnection.java)
dany giguere
05/09/2022, 10:37 PMfun delete(id: Int) = transaction {
CarEntity[id].delete()
}
How can I return true if it worked, else false ?
Using DSL I can do : `
Posts.deleteWhere { Posts.id eq id } > 0
but it doesn’t work with DAOAllan Galarza
05/10/2022, 4:08 PMUPDATE server_premium
SET expiration = expiration + $1
WHERE server_id = $2
RETURNING expiration
Where $1 is a python timedelta, that was converted to a Postgresql Interval
I'm trying to figure out how to do it in exposed.dany giguere
05/15/2022, 2:46 PMval user = userDSL.show(id)
call.respond(mapOf("user" to user))
but it won’t let me do
call.respond(user)
I get this error: Type mismatch: inferred type is User? but TypeVariable(T) was expected
why ?ESchouten
05/16/2022, 2:49 PMRuben Holen
05/17/2022, 12:44 PMjava.lang.NullPointerException
being thrown. It's only a few hundred out of many millions of calls, but it's still odd. This column is definitely not nullable, and I have confirmed there is proper data in every row. Anyone else seen this?
java.lang.NullPointerException
at org.jetbrains.exposed.dao.Entity.lookup(Entity.kt:193)
at org.jetbrains.exposed.dao.Entity.getValue(Entity.kt:173)
at com.company.user.data.Profile.getBirthDay(Profile.kt:19)
It's looks like this in code:
object ProfileTable : LongIdTable("profile") {
val birthDay = timestamp("birthDay")
// etc
}
class Profile(id: EntityID<Long>) : LongEntity(id) {
companion object : LongEntityClass<Profile>(ProfileTable, Profile::class.java)
var birthDay by ProfileTable.birthDay
// etc
}
Dario Pellegrini
05/18/2022, 10:18 AMfindById
I see a large number of SELECT queries instead of a single one. This could be a problem if server and database are not in the same network. Is there any way to force Exposed use a single query?
class HighlightDAO(id: EntityID<Int>): IntEntity(id) {
companion object : IntEntityClass<HighlightDAO>(Highlights)
val video by VideoDAO referencedOn Highlights.video
val preview by FileDAO referencedOn Highlights.preview
val title by Highlights.title
var createdAt by Highlights.createdAt
var match by MatchDAO referencedOn Highlights.matchId
var players by PlayerDAO via HighlightsPlayers
val events by HighlightEventDAO referrersOn HighlightEvents.highlightId
val homeScore by Highlights.homeScore
val awayScore by Highlights.awayScore
val empty by Highlights.empty
}
...
HighlightDAO.findById(highlightId)
Rodrigo Silva
05/27/2022, 9:18 PMReuben Jacobs
05/31/2022, 3:13 PMignore=True
on batchInsert
work for postgres? I seem to be getting an error on the insert for duplicate key, but I thought the ignore flag would take care of this...Raphaël K
06/01/2022, 11:19 AMWITH ten_parents AS (SELECT * from parent LIMIT 10)
SELECT *
FROM ten_parents p
LEFT JOIN child c
ON c.parent_id = p.id
The goal here is to limit a join request but only for the parents, as they can have several children 🙂Gustav Elmgren
06/02/2022, 9:36 AMColumn<EntityId<T>>
to ExpressionWithColumnType<T>
in some way?Simon Nozaki
06/12/2022, 11:39 PM./gradlew test
as mentioned in wiki.
But some tests failed. I understood that before tests, test classes download some database images, and it seems that test scripts(?) could not build docker images.
Would you please tell me how to run tests succesfuly?Gustav Elmgren
06/17/2022, 11:46 AMtransaction
to a variable and then something like transaction.begin()
and transaction.commit()
?aryeh
06/21/2022, 11:45 PMaryeh
06/21/2022, 11:45 PMaryeh
06/21/2022, 11:45 PMaryeh
06/21/2022, 11:55 PMorg.jetbrains.exposed:exposed-core:0.38.2
instead of org.jetbrains.exposed:exposed:0.17.14
aryeh
06/22/2022, 10:10 PMTable()
?
In particular, say I want to do SomeTable.insert { ... }
-- then I need to import import org.jetbrains.exposed.sql.*
to get the insert
extension
This means, say, if I want to do this operation some place other than the SomeTable
impl itself, I have that broad import
statement
This is different coming from popular ORMs in ruby, django -- not a bad thing per se
Three ways to structure I can think of:
• write wrapper instance methods for the the SomeTable
that call insert under the hood
• do the broad import
• something else?
I'm tentatively inclined to do the latter -- thoughts?aryeh
06/22/2022, 10:19 PMSomeTable.id.count()
-- how do I get as int?Rodrigo Silva
06/24/2022, 5:04 PMSELECT schema_name FROM information_schema.schemata WHERE schema_name = 'schema';
Raf Szałański
06/27/2022, 11:27 AMColumn<EntityID<UUID>>
as Column<UUID>
? the function I’m trying to write isn’t really concerned whether something is a primary key or not. backend I’m using is psqlPoisonedYouth
07/11/2022, 8:00 PMRaphael TEYSSANDIER
07/18/2022, 1:50 PMINSERT INTO gateways (gateway_id, gateway_sub_type, gateway_type, migration_status) VALUES ('VIRT048', 14, 15, 0) ON DUPLICATE KEY UPDATE gateway_id=VALUES(gateway_id), gateway_type=VALUES(gateway_type), gateway_sub_type=VALUES(gateway_sub_type), migration_status=VALUES(migration_status)
I get ERROR: syntax error at or near “DUPLICATE”
But with an online checker, it says it’s correctWyatt Kennedy
07/19/2022, 1:18 AMWyatt Kennedy
07/19/2022, 1:18 AMEndre Deak
07/19/2022, 7:48 AM