Hey folks. Trying to figure out why accessing the...
# announcements
r
Hey folks. Trying to figure out why accessing the
keyvalue
val inside this object is a problem:
Copy code
class Tables(val session: Session) {   
   val queries = object {
        val keyvalue = object {
            val insert = prepare("INSERT INTO keyvalue (id, value) values (?, ?)")
            val select = prepare("SELECT * from keyvalue WHERE id = ?")
        }
        val timeseries = object {
            val insert = prepare("INSERT INTO timeseries (id, c, data) values (?, ?, ?)")
            val selectPartition = prepare("SELECT * from timeseries WHERE id = ?")
            val selectPartitionReverse = prepare("SELECT * from timeseries WHERE id = ? order by c DESC")
        }
    }
}
I’m not able to do essentially this:
Copy code
tables = Tables(session)
tables.queries.keyvalue
anyone know why?
s
not sure if you come from a Swift background or something similar where you’d be able to access the properties of anonymous objects like this, but this isn’t legal code in this context. The compiler cannot determine the shape of the object without it adhering to an interface or otherwise having it be typed
r
ok. thanks for the quick answer!
Hmm… looks like you can’t create anonymous objects that implement multiple interfaces either
m
are you sure? IIt seems to me it’s possible for an object to implement interfaces, it works: https://pl.kotl.in/oNXzewedk
Nested access works as well: https://pl.kotl.in/LmGnJ4sQ2
r
I’m not even sure what I was doing at this point, sorry for the absurdly long non-response
m
no worries, it’s always a chance to learn something 😉