https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
exposed
  • n

    nilTheDev

    10/21/2021, 4:35 PM
    https://www.marcobehler.com/guides/jdbc https://www.marcobehler.com/guides/java-databases These are the two articles. Must read for everyone beginning with Databases in the JVM world. I would also write an article on this for new Kotlin programmers who are starting with databases to save them from the nightmare I faced.
    c
    • 2
    • 1
  • s

    subashz

    10/26/2021, 4:33 PM
    I need to implement pagination and this issue has been bugging me for hours now.
    a
    • 2
    • 1
  • e

    Emery Tanghanwaye

    10/26/2021, 11:34 PM
    heya all, i'm using the exposed kotlin dao, with a basic intidtable. how can i at runtime create tables based on the schema of that table with different names of my choosing?
    t
    • 2
    • 1
  • d

    dave08

    10/28/2021, 11:31 AM
    It would be great if SchemaUtils.drop and .create would be smart enough to run the list in the varargs version in an order that would work using references info to know with foreign keys would get in the way...
    e
    t
    • 3
    • 4
  • s

    spand

    10/29/2021, 7:11 AM
    What is the difference between ie.
    booleanParam()
    and
    booleanLiteral()
    ? I can look at the code but the different use cases escape me. They seem extremely similar
    t
    • 2
    • 2
  • t

    than_

    11/01/2021, 1:23 PM
    I've found weird transaction behaviour on MYSQL. having
    object TransactionTestTable: LongIdTable(){
        val foo = integer("foo").check { it greater 0 }
    }
    when I do
    newSuspendedTransaction {
        TransactionTestTable.insert { it[foo] = 1 }
        throw IllegalStateException("FAIL")
    }
    the transaction performs a rollback correctly and nothing gets inserted into the table but when I do
    newSuspendedTransaction {
        TransactionTestTable.insert { it[foo] = 1 }
        TransactionTestTable.insert { it[foo] = 0 }
    }
    the transaction still fails, but the first value gets inserted in the database. Is this intentional or a bug?
    b
    • 2
    • 8
  • n

    nordiauwu

    11/02/2021, 12:16 PM
    Is there a changelog for 0.36.1 somewhere?
    t
    • 2
    • 2
  • j

    Jeff

    11/03/2021, 1:08 PM
    How do I generate a unique id like INV0001 using exposed?
    t
    • 2
    • 4
  • h

    Hugo Jonker

    11/09/2021, 2:04 PM
    For example: right now I have problem with how to use aliases. I don't fully get them and I'm not good enough at kotlin to understand it from reading Exposed source code (I tried). How do you use alias to create function transforming ResultRow to Domain data?
    t
    • 2
    • 5
  • d

    dave08

    11/10/2021, 3:06 PM
    I have a very complex set of relationships of a bunch of tables, and from table A, I want to be able to access A.B.C.D.name... it'd be a pity to have to create an entity for each one, load them all and traverse them all just to access that field's value...
    t
    • 2
    • 6
  • c

    crummy

    11/10/2021, 8:57 PM
    some thoughts about Exposed on Reddit (not my post): https://www.reddit.com/r/Kotlin/comments/qqp87z/thoughts_aloud_about_exposed/
    d
    d
    • 3
    • 2
  • d

    dave08

    11/11/2021, 4:23 PM
    @tapac How could I be running into this issue https://github.com/JetBrains/Exposed/issues/186 when I'm currently holding by
    com.h2database:h2:{require 1.4.200; reject _} -> 1.4.200
    ...?
    t
    • 2
    • 6
  • a

    Attila Nagy

    11/15/2021, 8:46 PM
    Hello Can any one help how can I do this simple SQL insert in Exposed INSERT into Table 1(c1,c2,c3) Select c1,c2,c3 from table2
    e
    • 2
    • 8
  • a

    Alexander Weickmann

    12/02/2021, 2:14 PM
    Hi all, not sure whether this channel or the ktor channel might be better suited for this question, but I'll give a try here first. We have a service that handles data for multiple customers. We want to improve data isolation by creating different database users for each of our customers. We must therefore tell Exposed to dynamically use different credentials when it retrieves a database connection. One of the provided Database.connect functions should allow us to do exactly that:
    fun connect(getNewConnection: () -> Connection, ...)
    We use ktor as our http backend and now the only problem is how we can get the auth information from ktor into this lambda. We are able to store the required info in the pipeline context of ktor. So what we specifically try right now is to get PipelineContext data into the getNewConnection lambda:
    Database.connect(getNewConnection = {
        val jdbcUrl = "jdbc:${DbConfig.jdbcProtocol}://${DbConfig.hostname}:${DbConfig.port}/${DbConfig.database}"
        val user = "" // TODO how to get the data from ktor pipeline context into this lambda here?
        val password = ""  // TODO how to get the data from ktor pipeline context into this lambda here?
        DriverManager.getConnection(jdbcUrl, user, password)
    })
    Has somebody tried such a thing already? We need to somehow make Exposed aware of the ktor pipeline context, so we can set the credentials for the database based on the rest call at hand. Any tips or suggestions at all would be very much appreciated.
    k
    • 2
    • 10
  • o

    Osmium

    12/03/2021, 2:23 PM
    Hi! I'm working on ClickHouse support for exposed, and the problem is that its
    javax.sql.Cnnection
    implementation supports only small subset of interface features. So, I wrote my own
    ExposedConnection
    implementatiion, but I don't know how to pass it in
    Database
    . In other words, how can I reimplement
    org.jetbrains.exposed.sql.statements.jdbc.JdbcConnectionImpl
    and pass it in
    Database.connect()
    ?
    s
    • 2
    • 2
  • h

    hfhbd

    12/07/2021, 2:59 PM
    Hey, after 2 years, H2 released a new version: 2.0.202, which has some incompatibles. Should Exposed support both versions, or only the latest one? Often, H2 db's are used for testing, so supporting latest version only would be possible. The maintainer of H2 also support the latest version only and won't backport any fixes. Currently, I tried to adopt the versions changes in Exposed and I have some problems with the MySQL mode, because it is very buggy from H2 and fixes are only available in latest H2 version.
    d
    • 2
    • 3
  • p

    Peter Scardera

    12/10/2021, 4:41 PM
    Hey! anyone know if Exposed supports OffsetDateTime as a column type? or any suggestions how to work around not being able to save a timezone would be really appreciated 🙂
    d
    h
    • 3
    • 4
  • f

    Filip Lastic

    12/15/2021, 9:50 AM
    Why the default transaction level for MSSQL is different that other databases?
    fun getDefaultIsolationLevel(db: Database): Int =
                when (db.vendor) {
                    SQLiteDialect.dialectName -> Connection.TRANSACTION_SERIALIZABLE
                    OracleDialect.dialectName -> Connection.TRANSACTION_READ_COMMITTED
                    PostgreSQLDialect.dialectName -> Connection.TRANSACTION_READ_COMMITTED
                    PostgreSQLNGDialect.dialectName -> Connection.TRANSACTION_READ_COMMITTED
                    else -> DEFAULT_ISOLATION_LEVEL
                }
    const val DEFAULT_ISOLATION_LEVEL = Connection.TRANSACTION_REPEATABLE_READ
    • 1
    • 1
  • м

    Марк Эпштейн

    12/17/2021, 5:17 PM
    Hello! There is a colleague who wanted to write in exposed such a thing as
    select * from (select "1" as id) as idSource left join demo on idSource.id=demo.ID ...<other 10 tables where this id could exist>.
    Write via full join and 10 conditions demo.id ="1" or demo 2.id ="1" he doesn't really want to. Maybe someone knows how (select "1" as id) as idSource can be written in exposed? join function accept ColumnSet as parameter. ColumnSet has Columns which refers to Table. But idSource is not table here. @tapac, Bogdan Panchenko gave me advise tag you under the question.
    t
    • 2
    • 1
  • d

    Deji

    12/19/2021, 1:39 AM
    Hi, I am kotlin/exposed newbie and I am having trouble inserting into a table with a foreign key reference. Please can someone tell me what I am doing wrong?
    object Profile : IntIdTable("profile", "id") {
      val externalId: Column<String> = varchar("external_id",
        255).uniqueIndex("external_profile_external_id_uindex")
    
      val profileUrl: Column<String?> = varchar("profile_url",
        255).uniqueIndex("external_profile_profile_url_uindex").nullable()
    
      val imageUrl: Column<String?> = varchar("image_url", 255).nullable()
    
      val uri: Column<String> = varchar("uri", 255).uniqueIndex("external_profile_uri_uindex")
    }
    
    object User : IntIdTable("user", "id") {
      val username: Column<String> = varchar("username",
        20).uniqueIndex("internal_user_username_uindex")
    
      val email: Column<String> = varchar("email",
        255).uniqueIndex("internal_user_email_uindex")
    
      val displayName: Column<String?> = varchar("display_name", 255).nullable()
    
      val externalProfileId: Column<Int> =
        integer("profile_id").references(Profile.id).uniqueIndex("internal_user_external_profile_id_uindex")
    }
    
    
    val profile = Profile.insert {
      it[externalId] = "externalId"
      it[profileUrl] = "profileUrl"
      it[imageUrl] = "imageUrl"
      it[uri] = "uri"
    }
    
    val user = User.insert {
      it[username] = "username"
      it[email] = "email"
      it[displayName] = "displauName"
      it[externalProfileId] = profile[id] // <--- this line fails to compile
    }
    I cant set the externalProfileId foreign key to the ID from the new profile created. is there a better way to do this? Thanks!
    d
    • 2
    • 4
  • h

    Hugo Jonker

    12/20/2021, 8:09 AM
    Hello, I set up batch insert in Exposed but is there an option setting batch size like in hibernate?
    t
    • 2
    • 2
  • j

    James Myers

    12/21/2021, 3:01 PM
    Hi folks. I was following the recommendation for server side timestamps by using the following:
    val updatedAt = datetime("updated_at").defaultExpression(CurrentDateTime())
    I was looking at the following chunk for using the
    EntityHook
    and it wasn’t clear how to leverage the
    CurrentDateTime
    here as well:
    EntityHook.subscribe { action ->
                if (action.changeType == EntityChangeType.Updated) {
                    action.toEntity(this)?.updatedAt = LocalDateTime.now(Clock.systemUTC())
                }
            }
    I’ve tried looking through the code/docs but wasn’t able to find an example of how to do this properly. Is there something obvious that I’m missing here, or do these two not work very well together. Any help would be appreciated. Thanks!
    d
    • 2
    • 3
  • k

    Khurram Malik

    12/31/2021, 8:45 PM
    I cannot update the expose dependencies reason being the IntIdTable primaryKey field is now final (in newer versions of the dependencies, from version 0.36.1 to be precise):
    /**
     * Identity table with autoincrement integer primary key
     *
     * @param name table name, by default name will be resolved from a class name with "Table" suffix removed (if present)
     * @param columnName name for a primary key, "id" by default
     */
    open class IntIdTable(name: String = "", columnName: String = "id") : IdTable<Int>(name) {
        final override val id: Column<EntityID<Int>> = integer(columnName).autoIncrement().entityId()
        final override val primaryKey by lazy { super.primaryKey ?: PrimaryKey(id) }
    }
    This field was earlier not final and we were able to override it for several tables by combining/linking two tables:
    object AnswersInQuestionTable : IntIdTable("answers_in_question"){
        val question = reference("question_id", QuestionsTable)
        val answer = reference("answer_id", AnswersTable)
        override val primaryKey = PrimaryKey(question, answer)
    }
    This is a an issue for our web service. Anyone who know what the best practice(s) are for resolving that?
    d
    • 2
    • 2
  • f

    Filip Lastic

    01/03/2022, 10:35 AM
    Hey. Please, is it possible to override isolation level by
    dataSource
    isolation? I am using HikariCP as datasource and I defined
    hikariDataSource.transactionIsolation = "TRANSACTION_READ_COMMITED"
    . But when I call
    transaction {
     val level = this.transactionIsolation
    }
    value of the
    level
    variable is different than isolation specified for dataSource..
    • 1
    • 1
  • d

    d.medina

    01/05/2022, 7:30 PM
    Has anyone tryed connecting to a postgres sql db on heroku? the URI Herohu gives me has the dialect as postgros but expose is looking for postgrosql. i been looking to see if i can config on or the other to play nice with one an other but i am having no luck so far
    • 1
    • 1
  • d

    dany giguere

    01/05/2022, 11:05 PM
    Hello everyone. I’m in a Ktor project and I’m trying to install exposed. In which file am I supposed to put this :
    val config = HikariConfig().apply {
        jdbcUrl         = "jdbc:<mysql://localhost/dbname>"
        driverClassName = "com.mysql.cj.jdbc.Driver"
        username        = "username"
        password        = "secret"
        maximumPoolSize = 10
    }
    val dataSource = HikariDataSource(config)
    Database.connect(dataSource)
    from the documentation here: https://github.com/JetBrains/Exposed/wiki/DataBase-and-DataSource
    e
    d
    • 3
    • 2
  • b

    brabo-hi

    01/07/2022, 6:02 AM
    Hi, can we use
    r2dbc
    with exposed
    d
    c
    • 3
    • 3
  • s

    Sourabh Rawat

    01/16/2022, 3:04 PM
    Why does this fail?
    @Test
        fun dbTest2() {
            Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver")
            transaction {
                SchemaUtils.create(Blogs)
            }
            transaction {
                Blog.all().also { println(it.toList()) }
                Blog.new {
                    title = "asd"
                    rawContent = "foo"
                }
                Blog.all().also { println(it.toList()) }
            }
        }
    with
    Table "BLOGS" not found (this database is empty)
    even though I can see that create table call executed before
    2022-01-16 20:32:57.273 [Test worker] DEBUG Exposed - CREATE TABLE IF NOT EXISTS BLOGS (ID INT AUTO_INCREMENT PRIMARY KEY, TITLE VARCHAR(100) NOT NULL, RAW_CONTENT TEXT NOT NULL, CREATE_DATE_TIME DATETIME(9) NOT NULL, UPDATE_DATE_TIME DATETIME(9) NOT NULL)
    2022-01-16 20:32:57.289 [Test worker] DEBUG Exposed - SELECT BLOGS.ID, BLOGS.TITLE, BLOGS.RAW_CONTENT, BLOGS.CREATE_DATE_TIME, BLOGS.UPDATE_DATE_TIME FROM BLOGS
    😒olved: 1
    • 1
    • 1
  • m

    martmists

    01/19/2022, 12:23 PM
    How do I check columns for null or set them to nullable values? table:
    object CommentTable : LongIdTable() {
        val post = reference("post", PostTable)
        val parent = optReference("parent", CommentTable)
        val author = reference("author", UserTable)
        val content = text("content")
        val created = datetime("created")
        val updated = datetime("updated")
    }
    but when doing
    CommentTable.parent eq null
    I get
    Overload resolution ambiguity: 
    public open fun <T : Comparable<TypeVariable(T)>, E : EntityID<TypeVariable(T)>?> ExpressionWithColumnType<TypeVariable(E)>.eq(t: TypeVariable(T)?): Op<Boolean> defined in org.jetbrains.exposed.sql.SqlExpressionBuilder
    public open fun <T> ExpressionWithColumnType<TypeVariable(T)>.eq(t: TypeVariable(T)): Op<Boolean> defined in org.jetbrains.exposed.sql.SqlExpressionBuilder
    d
    • 2
    • 12
  • j

    Jonathan Derin

    01/19/2022, 3:04 PM
    Are others experiencing this problem as well? https://github.com/JetBrains/Exposed/issues/1366 We’ve had to downgrade is it became a noticeable performance problem for us. Somehow this issue is not getting any traction though.
    • 1
    • 1
Powered by Linen
Title
j

Jonathan Derin

01/19/2022, 3:04 PM
Are others experiencing this problem as well? https://github.com/JetBrains/Exposed/issues/1366 We’ve had to downgrade is it became a noticeable performance problem for us. Somehow this issue is not getting any traction though.
@tapac it would be great to get some feedback here as to how we can help to get this fixed
View count: 12