Thread
#exposed
    z

    ziad

    4 years ago
    This is what I went for, is there a cleaner or more idiomatic way to do it?
    return transaction {
               //Check if a user with this device id exists       
                val userIdEntity = Users.select {
                    Users.deviceId eq deviceId
                }.map { it[Users.id] }.firstOrNull()
    
                //Assign the user id 
                val userId =
                        if(userIdEntity != null) {
                            userIdEntity.value
                        } else
                        {
                            Users.insertAndGetId {
                            //...
                            }.value
                        }
            }
    tapac

    tapac

    4 years ago
    val userIdEntity = Users.select {
                    Users.deviceId eq deviceId
                }.limit(1).singleOrNull()?.get(Users.id]
    But your code is fine too.