Skip to content

Commit

Permalink
Update database in benchmark version
Browse files Browse the repository at this point in the history
  • Loading branch information
serbelga committed Jun 16, 2024
1 parent 2bc3ba1 commit 71282f9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions common/database/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ kotlin {

android {
namespace = "dev.sergiobelda.todometer.common.database"

buildTypes {
create("benchmark") {
signingConfig = getByName("debug").signingConfig
matchingFallbacks += listOf("release")
}
}
}

sqldelight {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,34 @@ import android.content.Context
import androidx.sqlite.db.SupportSQLiteDatabase
import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.driver.android.AndroidSqliteDriver
import java.io.File
import java.io.FileNotFoundException
import java.io.FileOutputStream

actual object DriverFactory {
lateinit var appContext: Context

actual fun createDriver(): SqlDriver {
val fileName = "todometer.db"
val database: File = appContext.getDatabasePath(fileName)

if (!database.exists()) {
try {
val inputStream = appContext.assets.open(fileName)
val outputStream = FileOutputStream(database.absolutePath)

inputStream.use { input ->
outputStream.use {
input.copyTo(it)
}
}
} catch (_: FileNotFoundException) {}
}

return AndroidSqliteDriver(
TodometerDatabase.Schema,
appContext,
"todometer.db",
fileName,
callback = object : AndroidSqliteDriver.Callback(TodometerDatabase.Schema) {
override fun onOpen(db: SupportSQLiteDatabase) {
db.execSQL("PRAGMA foreign_keys = ON;")
Expand Down
Binary file not shown.

0 comments on commit 71282f9

Please sign in to comment.