https://kotlinlang.org logo
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
squarelibraries
  • a

    ankushg

    12/01/2021, 12:56 AM
    Is there a way to specify a mapper for a query that selects a single column? This is mostly for aesthetics so patterns match regardless of the number of items returned -- I can obviously
    map
    the list after I've executed the query
    a
    • 2
    • 2
  • p

    Philip Dukhov

    12/02/2021, 11:56 AM
    I'm using MySQL database, and have this code for migration:
    val dataSource = HikariDataSource(datasourceConfig)
    val driver = dataSource.asJdbcDriver()
    driver.migrate(Database.Schema)
    //...
    private class SqlDriverTransacter(driver: SqlDriver) : TransacterImpl(driver)
    
    fun SqlDriver.migrate(schema: SqlDriver.Schema) {
        val sqlDriverTransacter = SqlDriverTransacter(this)
        // ...
        sqlDriverTransacter.transaction {
        	// ...
        }
    }
    I don't remember exactly where from this code came from, it looks kind of like this one. The problem is that in case of a crash inside
    transaction
    , the database is not getting rolled back. When in my migration I have
    create table
    and then some action, if the action fails, next time I'm getting a crash
    Table already exists
    . I've tried catching the error inside
    transaction
    and running
    rollback
    manually, but this had no effect.
    a
    • 2
    • 1
  • p

    Paul Griffith

    12/03/2021, 6:30 PM
    Is there a trick to using types like BIGINT in a .sq file for use on Postgres? https://cashapp.github.io/sqldelight/jvm_postgresql/types/ Documentation suggests it should work, but code generation fails:
    schema.sq line 17:12 - <type name real> expected, got 'BIGINT'
    I'm using 1.5.3
    j
    • 2
    • 5
  • j

    jw

    12/04/2021, 5:56 AM
    there is no Molecule compiler plugin
    s
    • 2
    • 3
  • j

    jw

    12/04/2021, 6:00 PM
    Our presenters do not retain state. You're free to hook up the regular save instance state stuff like Compose UI does though.
    s
    s
    p
    • 4
    • 12
  • j

    John Aoussou

    12/05/2021, 1:35 PM
    Is there a way to dynamically switch between tables that have the exact same schema but different names in SQL Delight? I have a database with one table per language I'm wondering whether it would be feasible to switch between tables when the user selects a language (I'm not sure how to go about doing that since the schema classes are automatically generated and are named the same as the table, so it doesn't seem like a generic class name can be used).
    d
    • 2
    • 3
  • j

    jw

    12/08/2021, 5:02 AM
    no. you would need to copy it from your apk into the database directory of your private apk files before opening.
    :thank-you: 1
    j
    • 2
    • 1
  • s

    saket

    12/10/2021, 7:42 PM
    You are using Compose for presentation logic, but aren’t using Compose for UI?
    by "you" are you referring to Square Block? or the library?
    s
    • 2
    • 2
  • r

    ralf

    12/12/2021, 9:48 PM
    Short answer is no, because for Anvil a “scope” only needs to be a class reference. It doesn’t need to be a Dagger
    @Scope
    . For example our scope annotation looks like that:
    @Scope
    annotation class SingleIn(val value: KClass<*>)
    The usage side looks similar to this:
    @SingleIn(AppScope::class)
    @ContributesTo(AppScope::class)
    @MergeComponent(AppScope::class)
    Anvil wouldn’t be able to make the connection that
    @SingleIn
    is the actual Dagger scope.
    d
    • 2
    • 8
  • c

    Colton Idle

    12/16/2021, 9:09 PM
    If I needed to cache something for "offline" mode for an api that doesn't send back any caching headers. Would you: 1. Write an interceptor that adds some sort of basic cache header so that even without a network connection the http client still returns data I can display on the screen 2. Just save my json response as a file and read from that if I'm "offline" Note: I know "offline" is not really a true state, but in my case my PM just wants data to show when the user is actually in airplane mode.
    k
    e
    • 3
    • 7
  • d

    d.medina

    12/21/2021, 9:46 PM
    SQLDelight for JVM is ether not seeing my .sq file, or the gradle tasks for not generating my database is failing and saying it is succesfull or maybe i have no clue whats going on
    h
    • 2
    • 1
  • p

    Paul Woitaschek

    12/23/2021, 10:20 AM
    What are the recommendations on testing flows? With runTest I always run into a TimeoutCancellationException. For example a very simple reproducer:
    @Test
      fun myTest() = runTest {
        flow {
          delay(10.milliseconds)
          emit(Unit)
        }.test {
          awaitItem() shouldBe Unit
        }
      }
    j
    • 2
    • 6
  • c

    Colton Idle

    12/30/2021, 4:11 PM
    I've got a requirement to make my deserialization crash during runtime on "internal" builds, but not crash on external builds when I get data over the wire that is null when it's not supposed to be null. So with moshi, unless I declare something as explicitly null, I will not be made to handle nullability in that type in my code (makes sense) but "moshi" will still give me a null value if it's sent explicitly over the wire. So now I basically have a fork in the road in deciding on how to move forward. 2 options from what I see: 1. For every model... create two models, put one in /external and one in /internal. The ones in /internal would not be nullable, while the ones in /internal would be nullable which would make me handle nullability, but I would crash on deserialization in internal builds. 2. I can do a "check" on my data when it comes down and just make everything nullable, but in my checking layer I would just verify that my data is in a good state. I could have sworn I read a stackoverflow answer from Jesse Wilson on this topic a while back and he basically said something along the lines of "instead of depending on your deserializer to do this sort of checking for you, you can just do it yourself and the checking would then not be "hidden" in your deserializer." Anyone got any opinions on how to move forward with this? I think I'm leaning on option 2. Make everything nullable (because even though my backend says "hey we won't send you null" sometimes it does get through. And then there are some other invariants I could assert. i.e. Hypothetical, but person age will never be 0. If you get zero something is terribly wrong. In that case, I could crash in internal builds, but I could set some kind of default (or remove the feature from the UI) in external builds. I would love to just always crash in both internal/external, but I was overruled on that. 😢
    j
    • 2
    • 2
  • t

    Tim Malseed

    12/30/2021, 10:32 PM
    Hi team, hope you don’t mind a Cashapp/Turbine question here. This is a cross-post from #coroutines b/c I’m not quite sure if Turbine is influencing the outcome here.. I’m having trouble with a unit test. I’m trying to validate the behaviour of a StateFlow. But, the StateFlow is only in this particular state until a certain suspend function completes. During testing, my test double uses a delay to simulate a long running task. But, due to the nature of 
    runBlockingTest()
     , this delay is skipped, so this function completes immediately, and the StateFlow essentially bypasses the value I’m trying to test.
    p
    • 2
    • 5
  • j

    Javier

    01/04/2022, 3:25 PM
    I have a library which is going to be transformed to KMP and for testing I have a few json files inside resources directory. If the library has no JS target, I could use Okio, but if it has JS, I should transform those json files to strings or I could use them via Okio?
    m
    • 2
    • 4
  • c

    Colton Idle

    01/04/2022, 5:23 PM
    I'm doing some testing using moshi and trying to see what happens when I have a field defined as
    val title: String = "default"
    , but then my server sends a number by accident. It seems like moshi will convert the json number into a String type. Is that right?
    p
    j
    • 3
    • 12
  • f

    Fanilog

    01/06/2022, 4:55 PM
    Hello 👋 , I’m trying to intercept the request body with OkHttp when I’m doing a call with wire-grpc. How can I decode the
    RequestBody
    after doing
    val buffer = Buffer()
    requestBody?.writeTo(buffer)
    buffer.readByteArray()
    ?
    j
    • 2
    • 2
  • b

    Benoit Quenaudon

    01/06/2022, 4:58 PM
    Need something similar to what https://github.com/mattprecious/protogram does. This is doable with Wire APIs
    f
    • 2
    • 4
  • d

    Dutch

    01/09/2022, 12:32 AM
    Using KotlinPoet, how would I create the ParameterSpec of class B in the following example?
    abstract class A(
        open var field1: String
    )
    
    abstract class B(
        override var field1 : String
    ) : A(field1)
    I tried to also create a corresponding PropertySpec for my class, but as a result I get the following:
    public abstract class B(
      override field1: String
    ) : A() {
      public override var field1: String
    }
    e
    • 2
    • 12
  • a

    alec

    01/10/2022, 1:52 PM
    what dialect are you on
    j
    • 2
    • 9
  • c

    Colton Idle

    01/10/2022, 6:24 PM
    If I was writing a feature/library that would intercept all network traffic and show it on the device (essentially building an on device charles proxy), it seems like I would use a network interceptor over an application interceptor. Is there anything that would still be hidden, or is it safe to say "an okhttp network interceptor would be able to show all of the same information as a typical desktop proxy (like charles)"
    p
    • 2
    • 1
  • c

    Colton Idle

    01/11/2022, 4:16 AM
    I updated android gradle plugin and android studio from alpha/canary 3 to alpha/canary 7. No other changes. Now after doing all sorts of nuking/restarting I'm left with these errors messages. I'm assuming there's no reason why okhttp and moshi wouldn't work with agp alpha 7 (released today)? I'm doing some more research on the android bugtracker to see if this is worth reporting, but figured id chime in here to see if anyone else upgraded to agp alpha 7 today. This error is actually in a java/kotlin lib. nothing android related in it. Edit: Should have mentioned my code actually still builds fine. just the IDE with these error messages.
    e
    • 2
    • 3
  • m

    Matti MK

    01/12/2022, 9:48 AM
    I’m working with SQLDelight and I have the following relation A
    1 to N
    B B
    1 to N
    C Sometimes I’ll need a
    List<A>
    , sometimes just a
    List<B>
    . Constructing the objects, like
    A
    , based on queries seems a bit confusing to me, so wondering if someone could point me a to a sample that implements something similar? Thanks 👍
    • 1
    • 2
  • j

    jessewilson

    01/13/2022, 12:41 PM
    I don't know about Postgres but for MySQL on servers at Cash App we never just call the database to apply schema changes. Instead we use gh-ost so the DB isn't locked and unavailable during the schema change
    👀 2
    s
    • 2
    • 2
  • x

    xxfast

    01/14/2022, 1:57 AM
    Hi all. Trying to use SqlDelight on a KMP library module, (which also targets
    js(IR)
    ). I’m making use of the npm-publish plugin to export my KMP library locally to npm, so that i can
    link
    these kotlin-js artefacts from pure js projects. However, when I invoke
    initSqlDriver()
    from jsMain, i get this on the console
    wasm streaming compile failed: TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.
    failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0
    Has anyone encountered this before?
    ✅ 1
    • 1
    • 1
  • d

    Derek Ellis

    01/14/2022, 2:07 AM
    Do you have sql.js as a dependency on your pure JS project?
    x
    h
    • 3
    • 19
  • c

    Colton Idle

    01/15/2022, 8:12 PM
    For handling a typical oauth flow from my server where I get a 401 and then I want to try to use my refresh token to get a new access token. Best to just handle in an interceptor (network or application) or just use the authenticator apis in okhttp?
    y
    • 2
    • 3
  • a

    alec

    01/18/2022, 9:17 PM
    but outside of sqlite i think most use
    deriveSchemaFromMigrations
    s
    p
    v
    • 4
    • 49
  • b

    Benoit Quenaudon

    01/25/2022, 6:28 PM
    What you wanna do with the iif?
    k
    • 2
    • 1
  • d

    Daniel Perez

    01/26/2022, 9:08 PM
    I see. On a
    FunSpec.returns()
    call I see I can use the ClassName by providing a String for a package and a String for the name of the type, but I’m unsure how to make sure it returns with a * parameter. Am I correct in going for
    ClassName
    here over
    FqName
    ? If so, how can I make sure it is parameterized by a *?
    • 1
    • 1
Powered by Linen
Title
d

Daniel Perez

01/26/2022, 9:08 PM
I see. On a
FunSpec.returns()
call I see I can use the ClassName by providing a String for a package and a String for the name of the type, but I’m unsure how to make sure it returns with a * parameter. Am I correct in going for
ClassName
here over
FqName
? If so, how can I make sure it is parameterized by a *?
I’ve figured it out and will leave this here in case anyone see’s this in the future. Use
parameterizedBy( STAR )
after creating the
ClassName.
View count: 5