Deybeer Gonzalez
Deybeer Gonzalez

Reputation: 1

sqldelight isn't generate the database with Compose Multiplatform with JS compiler

I have a proyect with compose multiplatform using sqldelight to manage the data base, Ios and Android are working fine but the JS web, execute fine but the database isn't init with the configured tables, and return the error WebWorkerException: {"message":"no such table: Configs","name":"Error"}.

this is my driver Class for JS module

actual class DatabaseDriverFactory : KoinComponent {
    actual suspend fun createDriver(): SqlDriver {
        val driver = WebWorkerDriver(
            Worker(
                js("""new URL("@cashapp/sqldelight-sqljs-worker/sqljs.worker.js", import.meta.url)""")
            )
        )
        try {
            MyDataBase.Schema.create(driver).await()
        }catch (e:Exception){
            println("error when create ${e.message}")
        }
       return driver
    }
}

my JS Gradle confiiguration

     jsMain.dependencies {

            implementation(libs.ktor.client.httpjs)
            implementation(libs.web.drive)
            implementation(npm("@cashapp/sqldelight-sqljs-worker", "2.0.2"))
            implementation(npm("sql.js", "1.10.3"))
            implementation(devNpm("copy-webpack-plugin", "12.0.2"))

        }

sqldelight config

sqldelight {
    databases {
        create("MyDataBase") {
            packageName.set("com.test.compose.mycompose")
            srcDirs.setFrom("src/commonMain/sqldelight")
            schemaOutputDirectory.set(file("src/commonMain/sqldelight"))
            generateAsync = true
            deriveSchemaFromMigrations.set(true)
            verifyMigrations.set(true)
        }
    }
}

I don't know if I miss some config.

I follow this documentation https://cashapp.github.io/sqldelight/2.0.2/js_sqlite/multiplatform/ to config my proyect, I updated to recent sql.js librarry and copy-webpack-plugin but nothing fix it.

this is my .sq file content

import kotlin.Boolean;


CREATE TABLE Configs(
    id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    firstFetchConfigs INTEGER AS Boolean NOT NULL
);

lastConfig:
SELECT * FROM
Configs
ORDER BY id DESC LIMIT 1;

insertConfigs:
UPDATE Configs SET firstFetchConfigs = :firstFetchConfigs WHERE id = :id;

INSERT INTO Configs(id, firstFetchConfigs)
VALUES (1, 0);

Upvotes: 0

Views: 189

Answers (0)

Related Questions