https://kotlinlang.org logo
#exposed
Title
# exposed
d

Das135

11/04/2020, 11:35 AM
Hi! Is it possible to use custom column with custom alias in exposed query? I mean column that is not in Table definition. I need something like this:
SELECT 'custom1' as custom, id, name, address FROM persons
b

Bogdan

11/04/2020, 4:34 PM
Copy code
object Persons : IntIdTable() {
    val name = varchar("name", 255)
    val address = varchar("address", 500)
}

fun main() {
    Database.connect("jdbc:h2:mem:regular;DB_CLOSE_DELAY=-1;", "org.h2.Driver")
    transaction {
        SchemaUtils.create(Persons)
        Persons.insert {
            it[name] = "Name"
            it[address] = "Addresss"
        }

        Persons.selectAll().forEach(::println)

        val custom = stringParam("custom1").alias("custom")
        Persons.slice(Persons.columns + custom)
            // or .slice(listOf(custom) + Persons.columns)  first custom
            .selectAll()
            .forEach { println(it[custom]) }
    }
}
👍 1
d

Das135

11/05/2020, 8:56 AM
Thank you!
stringParam
is exactly what I need 🙂
8 Views