【问题标题】:Increase performance of kotlin SQLite using PRAGMA commands使用 PRAGMA 命令提高 kotlin SQLite 的性能
【发布时间】:2021-10-14 17:04:53
【问题描述】:

我尝试使用 jetbrains.exposed 库在 Kotlin 中创建并连接到 SQLite 数据库。

import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.transactions.transaction

private fun provideSqliteDatabase(databaseConfig: DatabaseConfig?): Database {
    val path = databaseConfig?.url ?: "./"
    File(path).mkdirs()

    logger.info("SQLite Database path: $path/database.db")
    return Database.connect("jdbc:sqlite:$path/database.db", "org.sqlite.JDBC")
        .apply {
            TransactionManager.manager.defaultIsolationLevel =
                Connection.TRANSACTION_READ_UNCOMMITTED
            provideTables()

        }
}

我尝试使用一些 PRAGMA SQLite 命令来提高我的数据库的性能。 如何设置这些配置,例如 set JOURNAL_MODE:

PRAGMA JOURNAL_MODE='OFF';

要点:我在 Ubuntu 20.04 上运行我的程序。

【问题讨论】:

    标签: sqlite kotlin kotlin-exposed


    【解决方案1】:

    您可以尝试使用journal_mode=OFF 扩展您的连接网址。 如果你检查SQLite driver tests你会发现它会自动解析和执行这些参数。

    【讨论】:

      【解决方案2】:

      我相信在这种情况下你必须编写简单的 SQL:

      transaction {
          exec("PRAGMA JOURNAL_MODE='OFF'", explicitStatementType = StatementType.EXEC)
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-02-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-11
        • 2016-10-23
        • 2019-09-20
        相关资源
        最近更新 更多