MatrixDev / Roomigrant

Automated Android Room ORM migrations generator with compile-time code generation
MIT License
373 stars 23 forks source link

Table names with a - leads to invalid code generation #14

Closed Firenox89 closed 3 years ago

Firenox89 commented 3 years ago

Hi,

I just tried your library. Unfortunately my table names are using - as a word separator. e.g. "device-config"

Generated code then looks like this, which the compiler complains about.

    val indices_device-config = HashMap<String, IndexInfo>()

    val tableInfo_device-config = TableInfo(schemeInfo, "device-config",
        "CREATE TABLE IF NOT EXISTS `device-config` (...)",
        indices_device-config)
    tables.put("device-config", tableInfo_device-config)
MatrixDev commented 3 years ago

thanks for reporting this issue. will try to fix it today.

Firenox89 commented 3 years ago

Thanks for the quick response.

I just had a look and I think placing a few backticks could solve it.

For my case, I think this would do the trick.

RoomigrantCompiler/src/main/java/dev/matrix/roomigrant/compiler/Database.kt#L112

            code.addStatement("val `%L` = %T()", indices, indicesType)
            code.addStatement("")

            code.addStatement("val `%L` = %T(%L, %S, %S, `%L`)", tableInfo, TableInfo::class, schemeInfo, table.name, table.createSql(), indices)
            code.addStatement("%L.put(%S, `%L`)", tablesMap, table.name, tableInfo)
            code.addStatement("")
MatrixDev commented 3 years ago

Yes, it would fix this issue but I also want to reduce number of variables. Fix was pushed to the new version 0.3.2.

Firenox89 commented 3 years ago

Wow, this was quick.

Thanks for your work👍🏻