Reputation: 4151
I am trying to use a custom enum class
as a column type in SqlDelight. My folder structure looks as follows:
The Model.sq
looks like this:
import kotlin.Boolean;
import my.package.model.CustomEnum;
CREATE TABLE IF NOT EXISTS job (
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
"state" TEXT AS CustomEnum NOT NULL,
"isDirty" INTEGER AS Boolean
);
The setup in gradle is this:
sqldelight {
databases {
create("OurDatabase") {
srcDirs("src/main/sqldelight")
packageName.set("my.package.model")
}
}
}
Generation itself works, I also added the EnumColumnAdapter<CustomEnum>
to the OurDatabase
stateAdapter
.
I can't compile the code and the reason is the generated Model.kt
class has the correct import copied over from the sq
file but it seems the import is not resolvable from the build/generated/sqlight/code/OurDatabase/commonMain
. If I look at it with IntelliJ it looks like only classes are resolvable that are either general kotlin/java classes or classes that are within the generated directory but none from my main code folder. The thing that is weird to me is where the commonMain
in the generated directory is coming from (this is a kotlin multiplatform project but we only use it for JVM (Desktop)).
I think my question might also be related to this, since I also had to reconfigure the directories for the generation to work: sqldelight database setup for Compose Desktop, generated code is in wrong package In both cases there is no shared projct, just a jvm main project. The question is, can we force sqldelight to generate the model classes in a way that the classes inside the desktop/jvm project are available.
Upvotes: 0
Views: 90
Reputation: 4151
If anybody runs into this, I created a commonMain
source root under src
and moved the enum in there.
Upvotes: 0