【发布时间】:2020-06-09 20:04:04
【问题描述】:
我正在尝试使用 Ktor 构建应用程序并使用 SQLite 公开。不幸的是,我的应用程序不断崩溃。
这是我的数据库连接:
class DatabaseFactory(connection: DatabaseConnection) {
init {
connect()
createSchema()
}
private fun connect() {
Database.connect("jdbc:sqlite:/path/to/file", "org.sqlite.JDBC")
TransactionManager.manager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE
}
private fun createSchema() {
transaction {
SchemaUtils.create(Images)
SchemaUtils.create(KeyValues)
Images.deleteAll()
}
}
suspend fun <T> dbQuery(block: () -> T): T =
withContext(Dispatchers.IO) {
transaction { block() }
}
}
// access db with
DatabaseFactory.dbQuery {
// do stuff
}
在运行我的应用程序时,我收到以下错误:
org.jetbrains.exposed.exceptions.ExposedSQLException: org.sqlite.SQLiteException: [SQLITE_BUSY] The database file is locked (database is locked)
【问题讨论】:
标签: sqlite kotlin ktor kotlin-exposed