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
  • m

    MichaelMalus

    01/14/2019, 4:28 AM
    Hey. Fairly new to kotlin in general, got an oddity: I can query with
    table.selectAll()
    just fine. Trying to SELECT WHERE (as in
    table.select(table.columname eq foobar)
    ), I get
    Unresolved reference: eq
    . What am I missing?
    t
    • 2
    • 1
  • r

    runjorel

    01/18/2019, 4:29 PM
    Hi all. Would there be an issues to `open`ing
    ResultRow
    ? Long story short I wanted to create a delegate class to ResultRow but I don’t believe its possible due to ResultRow not being open.
    t
    • 2
    • 2
  • k

    Kevin

    01/20/2019, 2:42 PM
    Hi all, I’m trying to return values as described in the wiki ( https://github.com/JetBrains/Exposed/wiki/Transactions#accessing-returned-values ), but I’m having trouble The following code successfully prints 10 rows:
    transaction(Connection.TRANSACTION_SERIALIZABLE, 1) {
        Message
            .slice(Message.text)
            .selectAll()
            .limit(10)
            .forEach { println(it) }
    }
    But when I try to return the rows and use them outside of the transaction, it doesn’t seem to work:
    val messages = transaction(Connection.TRANSACTION_SERIALIZABLE, 1) {
        Message
            .slice(Message.text)
            .selectAll()
            .limit(10)
            .toList()
    }
    
    messages.forEach { println(it) }
    I’m getting
    java.lang.IllegalStateException: No transaction in context
    . When I set a breakpoint after the transaction,
    messages
    has length 10, but trying to access any elements throws an exception. I’m pretty new to this and wasn’t able to find anything by googling. Could someone help me figure out what I have wrong?
    t
    • 2
    • 3
  • m

    Marcin Wisniowski

    01/23/2019, 5:35 PM
    I'm using DAO, is the only solution to use DSL and then
    wrapRows
    back?
    t
    • 2
    • 2
  • t

    Tasos Stamadianos

    01/24/2019, 12:18 AM
    Hi there, I'm using a database with
    PostGIS
    support, and I'd like to call a
    PostGIS
    function during an insert, but I really can't figure out how to do this. I've seen examples involving
    ExpressionWithColumnType
    , but nothing that actually uses this function during an
    insert
    in a
    transaction
    . Some relevant code:
    abstract class SQLFunction<T>(override val columnType: IColumnType) : ExpressionWithColumnType<T>()
    
    class ST_Centroid(private val poly: MultiPolygon): SQLFunction<Point>(PointColumnType()) {
        override fun toSQL(queryBuilder: QueryBuilder) = "ST_Centroid($poly)"
    }
    I'm trying to do this now:
    [DbFields.center] = ST_Centroid(boundaryPoly)
    where
    boundaryPoly
    is a PostGIS multipolygon. Any help would be greatly appreciated 🙂
    t
    • 2
    • 2
  • a

    APXEOLOG

    01/26/2019, 12:57 AM
    Hello guys, how do i select max value of a specific column?
    k
    t
    • 3
    • 2
  • h

    hyukchan

    01/27/2019, 1:30 PM
    Hi guys, I'm having connection timed out after some minutes ... Is there any conf to set to make it try to reconnect by itself ?
    t
    • 2
    • 1
  • e

    Edouard Goossens

    01/28/2019, 9:55 PM
    Hi everyone, I’m pretty new to exposed, and I’m wondering if there’s a way to do something equivalent to:
    SELECT field1, field2, field2-field1 AS diff FROM table
    using DAO. Thanks!
    t
    • 2
    • 2
  • k

    Kevin

    01/29/2019, 8:10 AM
    Is it possible to do something like this with the DSL?
    select date, message.ROWID, id, text, filename, is_from_me, mime_type
    from message
           left join handle on message.handle_id = handle.ROWID
           inner join chat_message_join c on message.ROWID = c.message_id and c.chat_id = 259
           left join message_attachment_join maj on message.ROWID = maj.message_id
           left join attachment a on maj.attachment_id = a.ROWID;
    I’m pretty new to exposed and SQL in general, so I’m not sure if this is even the right way to do things in SQL.
    t
    • 2
    • 4
  • a

    Alexander Potukar

    01/30/2019, 10:39 AM
    I have an "updated_at" attribute in a PostgreSQL table updated by a trigger, so I just want to read this attribute but I want to ignore it when writing an entry via Exposed. One solution would be having two classes, one read model and one write model. However, is there a solution with Exposed to exclude a non-nullable field when it comes to inserting data?
    t
    • 2
    • 2
  • b

    bjonnh

    02/02/2019, 12:26 AM
    what is a good way to test for database-related code (using JUNIT5 if it matters)
    t
    • 2
    • 2
  • s

    samir

    02/06/2019, 10:28 AM
    Is it possible to get this to work with exposed in a transaction block?
    SET @total = 2; 
    PREPARE STMT FROM "SELECT * FROM my_table LIMIT ?"; 
    EXECUTE STMT USING @total;
    I know that this is not type safe and that it is better to use DSL/DAO but the requirements is that statements should be defined as strings from an admin interface.
    Exception in thread "main" org.jetbrains.exposed.exceptions.ExposedSQLException: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PREPARE STMT FROM "SELECT * FROM my_table LIMIT ?";
    EXECUTE STMT USING @total' at line 2
    SQL: [SET @total = 2;
    PREPARE STMT FROM "SELECT * FROM my_table LIMIT ?";
    EXECUTE STMT USING @total;]
    t
    • 2
    • 2
  • k

    Kevin

    02/08/2019, 8:49 AM
    connection check
    s
    t
    • 3
    • 11
  • t

    timm

    02/10/2019, 8:41 PM
    is there anything i have to do to get exposed to call a sequence for id generation besides declating the id column as follows?
    override val id: Column<EntityID<Long>> = long("id").autoIncrement("hibernate_sequence").primaryKey().entityId()
    • 1
    • 2
  • h

    Hasan

    02/11/2019, 2:12 PM
    Hi everyone, This might be a very specific problem, or I might be doing something wrong. I am playing around with
    Exposed
    and trying to use it with
    postgresql
    . I imported the latest verison of the
    postgresql jdbc driver
    using the maven dependency:
    maven
    <dependency>
    	<groupId>org.postgresql</groupId>
    	<artifactId>postgresql</artifactId>
    	<version>42.2.5.jre7</version>
    	<type>bundle</type>
    </dependency>
    And I attempted to connect to the database using:
    kotlin
    Database.connect(
    	"jdbc:<postgresql://localhost:5432/my_db>", 
    	driver = "org.postgresql.Driver", 
    	user = "postgres", 
    	password = "welcome")
    And this is the error I'm getting:
    Exception in thread "main" java.lang.ClassNotFoundException: org.postgresql.Driver at
    java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) at 
    java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190) at 
    java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499) at 
    java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:291) at 
    org.jetbrains.exposed.sql.Database$Companion.connect(Database.kt:112) at 
    org.jetbrains.exposed.sql.Database$Companion.connect$default(Database.kt:111) at 
    com.example.test.ExposedTest.connect(ExposedTest.kt:30) at com.example.test.HelloKt.main(Hello.kt:5)
    Can you spot what I might be doing wrong? Thanks in advance!
    👍 1
    t
    t
    • 3
    • 4
  • p

    pjagielski

    02/13/2019, 11:35 AM
    Hi, I wrote a post how we use Exposed at TouK, take a look 😉 https://medium.com/@pjagielski/how-we-use-kotlin-with-exposed-at-touk-eacaae4565b5 https://www.reddit.com/r/Kotlin/comments/aq45o6/how_we_use_kotlin_with_exposed_for_sql_access_at/
    🤘 2
    👍 2
    t
    s
    • 3
    • 2
  • k

    Kevin

    02/18/2019, 11:12 AM
    I want to log how long it takes to execute statements. I made a class that implements
    StatementInterceptor
    and overrode the
    beforeExecution
    and
    afterExecution
    methods. Is this the right approach? Or am I missing some functionality that is already built in?
    s
    • 2
    • 2
  • t

    tjb

    02/19/2019, 4:19 AM
    or is there docs on how to use exposed with a data class?
    • 1
    • 3
  • t

    tjb

    02/19/2019, 6:38 AM
    return transaction {
          PostDAO.wrapRows(
            Posts
              .innerJoin(PostsTags, {Posts.id}, {<http://PostsTags.post|PostsTags.post>})
              .innerJoin(Tags, {Tags.id}, {PostsTags.tag})
              .selectAll()
              .andWhere {
                Posts.title like "%$query%" or (Tags.name inList tags)
              }
              .withDistinct()
          ).map {
            it.toModel()
          }
          .distinct()
          .toList()
        }
    t
    • 2
    • 2
  • l

    lovis

    02/20/2019, 2:24 PM
    Hey there 🙂 I wondered what’s the rationale behind not matching the common sql-syntax with the
    select
    clause. Someone who’s used to sql would expect the dsl to work something like this:
    val gamailUsers = Users.select(id, name, email)
      .where { email like "%@gmail.com"}
      .map { ... }
    But instead expose uses
    slice
    to do the projection. And select to do the selection. Why is this? I don’t realy have an opinion, I just want to know what the reason behind this decision was.
    t
    • 2
    • 4
  • v

    Vinicius Carvalho

    03/01/2019, 9:05 PM
    15:58:19.284 [main] DEBUG Exposed - SELECT products.upc, products.sku, products.name, products.price, products.type, products.manufacturer, products.description, products.model, products.image, products.last_updated FROM products WHERE products.upc = 12
    SQL: SELECT products.upc, products.sku, products.name, products.price, products.type, products.manufacturer, products.description, products.model, products.image, products.last_updated FROM products WHERE products.upc = 12
    15:58:40.625 [main] WARN Exposed - Transaction attempt #1 failed: Invalid argument value: java.io.NotSerializableException. Statement(s): null
    java.sql.SQLException: Invalid argument value: java.io.NotSerializableException
    t
    • 2
    • 4
  • a

    asad.awadia

    03/03/2019, 9:16 PM
    Is it possible to concat two columns and then use that combined with an inList? E.g
    area_code_column + phone_number_column inList listOf(...)
    t
    • 2
    • 4
  • b

    bdawg.io

    03/04/2019, 6:44 PM
    Are there any examples of using Exposed without using thread local?
    t
    • 2
    • 1
  • g

    galex

    03/05/2019, 5:55 AM
    Would be nice to have that in the documentation!
    t
    • 2
    • 2
  • g

    galex

    03/06/2019, 7:46 AM
    How do I query table B to count how many rows have my id from Table A? Basically a calculated field based on another select?
    t
    • 2
    • 4
  • s

    SrSouza

    03/06/2019, 4:52 PM
    Hi guys, I want to know something about Exposed DAO How I can update the object after change him
    daoObj.name = "new Name"
    transaction(database) {
       daoObj.update()
    }
    Something like this have?
    t
    • 2
    • 4
  • g

    galex

    03/08/2019, 8:01 AM
    I see there’s a check function on a field (Column<T>), is there an example using this somewhere?
    s
    • 2
    • 4
  • c

    cedric

    03/10/2019, 10:42 PM
    Exposed doesn't seem to support UPSERT. is that correct? If it is, what's the most idiomatic way to insert a row if it's not already present, or update it otherwise?
    t
    • 2
    • 1
  • s

    spand

    03/14/2019, 9:35 AM
    How do I set the default value to
    null
    of a
    .nullable()
    column ? Many of these decorating functions are defined as
    fun <T:Any> Column<T>.default(
    t
    • 2
    • 2
  • s

    spand

    03/14/2019, 9:51 AM
    Another thread: What is the use case for having
    InsertStatement.get
    return
    T?
    ? The only use in the project that ought to use this functionality at all is
    fun <Key:Comparable<Key>, T: IdTable<Key>> T.insertIgnoreAndGetId
    . It seems to me that it ought to be changed to
    T
    and instead define a
    InsertStatement.tryGet
    for the much rarer use so can avoid having !! just to retrieve a generated key.
    t
    • 2
    • 2
Powered by Linen
Title
s

spand

03/14/2019, 9:51 AM
Another thread: What is the use case for having
InsertStatement.get
return
T?
? The only use in the project that ought to use this functionality at all is
fun <Key:Comparable<Key>, T: IdTable<Key>> T.insertIgnoreAndGetId
. It seems to me that it ought to be changed to
T
and instead define a
InsertStatement.tryGet
for the much rarer use so can avoid having !! just to retrieve a generated key.
t

tapac

03/19/2019, 6:57 AM
Nullable columns could produce
null
on insert and that's not the 'null == value was absent from insert'
s

spand

03/19/2019, 9:08 AM
But since
T
isnt contrained to
Any
it would just be ie.
Int?
which would work. Or I am not understanding you correctly. I have submitted a pull request with the change and a test that shows retrieval of null values.
👌 1
View count: 4