Can someone please help me see what I am doing wro...
# getting-started
s
Can someone please help me see what I am doing wrong here? I was trying to extract out a function to an extension function with generics and it does not think that TimespanTable is of type BaseUniverseTableTimespan,Any?
Copy code
object TimespanTable : Table("timespan"), BaseUniverseTable<Timespan, UByte>  {
    override val universeId: Column<UInt> = universeIdCol()
    override val id: Column<UByte> =  ubyte("id")
    val timespanId = ubyte("timespan_id")
    val name = varchar("name", 100)

    override val primaryKey = PrimaryKey(universeId, timespanId)

    override fun rowToData(row: ResultRow) = Timespan(
        id = row[timespanId],
        name = row[name],
    )

    //This works, but not when I extract to extension function
//    suspend fun selectAllForUniverseId(universeIdz: UInt) :  List<Timespan>  =
//    DatabaseSingleton.dbQuery {
//        selectAll().where { universeId eq universeIdz }.map { rowToData(it) }
//    }

}

suspend fun < T, D>  T.selectAllForUniverseId(universeIdz: UInt) :  List<D>  where T: Table, T: BaseUniverseTable<D,Any> =
    DatabaseSingleton.dbQuery {
        selectAll().where { universeId eq universeIdz }.map { rowToData(it) }
    }

val a : List<Timespan> = runBlocking {  TimespanTable.selectAllForUniverseId<TimespanTable, Timespan>(1u) }
val b : List<Timespan> = TimespanTable.selectAllForUniverseId(1u)
j
> It doesn't think that Timespan table is of type
BasicUniverseTable<Timespan, Any>
? > Why would it? Isn't
TimespanTable
a
BasicUniverseTable<Timespan, UByte>
? What's the variance of the second type parameter of
BasicUniverseTable
? Is it marked
out
?
s
You are right, that is the problem... 😮‍💨 It wasn't marked out.