I'm trying to build an application using Ktor and Exposed with SQLite. Unfortunately my application keeps crashing.
This is my database connection:
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
}
While running my application I get the following error:
org.jetbrains.exposed.exceptions.ExposedSQLException: org.sqlite.SQLiteException: [SQLITE_BUSY] The database file is locked (database is locked)