使用自定义JdbcSqliteDriver路径时出错

问题描述 投票:0回答:1

我的错误:

Caused by: org.koin.core.error.InstanceCreationException: Could not create instance for '[Singleton:'data.local.sqldelight.AppDatabase']

我会立即解释说,使用

JdbcSqliteDriver.IN_MEMORY
它可以爆炸

我正在实施

DatabaseDriberFactory
:

actual class DatabaseDriverFactory {
    actual fun createDriver(): SqlDriver {
        val databasePath = File(System.getProperty("java.io.tmpdir"), "${DatabaseHelper.DATABASE_NAME}.db")
        println(databasePath.path)
        val driver = JdbcSqliteDriver(
            url = "jdbc:sqlite:test.db",
            properties = Properties().apply { put("foreign_keys", "true") }
        ).also {
            AppDatabase.Schema.create(it)
        }
        return driver
    }
}

Koin.kt

 val databaseModule = module {
    single {
        createDatabase(driver = get())
    }
    single<ITeamDao> { TeamDao() }
}

稍后该模块将全部初始化


build.gradle.kts

sqldelight {
    databases {
        create("AppDatabase") {
            packageName.set("data.local.sqldelight")
            srcDirs.setFrom("src/commonMain/kotlin")
//            project.set(listOf("kotlin"))
//            schemaOutputDirectory = file("src/commonMain/sqldelight/schema")
        }
    }
}

我试图找到如何解决这个错误,但我找不到

我也收到以下错误:

Caused by: org.sqlite.SQLiteException: [SQLITE_CONSTRAINT_FOREIGNKEY] A foreign key constraint failed (FOREIGN KEY constraint failed)

kotlin jdbc jvm sqldelight
1个回答
0
投票

我遇到了两次这个问题,第一次是在创建数据库之前开始填充数据库时。还有第二个

generateAsync.set(true)

© www.soinside.com 2019 - 2024. All rights reserved.