• g

    Gustav Elmgren

    1 month ago
    Hi guys, I have some trouble with Kotlin, more then exposed maybe, so it might be the wrong channel. But lets say I have the following:
    Flights
        .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) ...
        }
    g
    phldavies
    +1
    7 replies
    Copy to Clipboard
  • Muhammad Talha

    Muhammad Talha

    1 month ago
    Hey all - beginner here: What’s the best way to decouple the DAO API from my app? It looks like the DAO API is both an entity and a DAO so I was wondering what the best way to go about this was. I could just resort to using the DSL API and have my own DAO object and Entity, but was hoping to avoid the boilerplate of mapping table properties to that entity. Thanks!
    Muhammad Talha
    PoisonedYouth
    4 replies
    Copy to Clipboard
  • p

    ptmt

    1 month ago
    What's the best way to understand if this executed statement was actually executed or just hit the entity cache? (If I understood correctly how it works)
    override fun afterExecution(
        transaction: Transaction,
        contexts: List<StatementContext>,
        executedStatement: PreparedStatementApi,
    ) {
        
    }
  • hhariri

    hhariri

    1 month ago
    Folks, I have a question if you don’t mind - what’s the main reason(s) you’ve chosen Exposed over other solutions?
    hhariri
    b
    +8
    10 replies
    Copy to Clipboard
  • g

    Gustav Elmgren

    1 month ago
    Hi guys, I had a method which calculated distance between two points, like so:
    fun 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
    .
    g
    3 replies
    Copy to Clipboard
  • zt

    zt

    4 weeks ago
    How would I set a default value for the markovConfig column on a Guild?
    object 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
    }
  • g

    Gustav Elmgren

    4 weeks ago
    Hi guys, I have some trouble understanding something, it is related to the
    timestamp
    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?
    g
    2 replies
    Copy to Clipboard
  • Hachemi Hamadi

    Hachemi Hamadi

    3 weeks ago
    SOLVED Hi, I am facing an issue when trying to compile a JavaFX project with Exposed. When using DSL APIs everything works well. But when I try to create entity for my rows and then call it like below:
    object 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 ?
    Hachemi Hamadi
    1 replies
    Copy to Clipboard