From f6756ef6b7dadb486724b2a501983f709b4be3fe Mon Sep 17 00:00:00 2001 From: Arkadii Ivanov <> Date: Sat, 17 Oct 2020 16:12:12 +0100 Subject: [PATCH] Persist desktop database --- .../sqldelight/example/todo/common/database/TodoDatabase.sq | 2 +- .../example/todo/common/database/TodoDatabaseDriverFactory.kt | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/todo/common/database/src/commonMain/sqldelight/example/todo/common/database/TodoDatabase.sq b/examples/todo/common/database/src/commonMain/sqldelight/example/todo/common/database/TodoDatabase.sq index d6ffeffcdf..e635976d70 100644 --- a/examples/todo/common/database/src/commonMain/sqldelight/example/todo/common/database/TodoDatabase.sq +++ b/examples/todo/common/database/src/commonMain/sqldelight/example/todo/common/database/TodoDatabase.sq @@ -1,4 +1,4 @@ -CREATE TABLE TodoItemEntity ( +CREATE TABLE IF NOT EXISTS TodoItemEntity ( id INTEGER PRIMARY KEY AUTOINCREMENT, orderNum INTEGER NOT NULL, text TEXT NOT NULL, diff --git a/examples/todo/common/database/src/desktopMain/kotlin/example/todo/common/database/TodoDatabaseDriverFactory.kt b/examples/todo/common/database/src/desktopMain/kotlin/example/todo/common/database/TodoDatabaseDriverFactory.kt index 266e549c7f..82e584ce38 100644 --- a/examples/todo/common/database/src/desktopMain/kotlin/example/todo/common/database/TodoDatabaseDriverFactory.kt +++ b/examples/todo/common/database/src/desktopMain/kotlin/example/todo/common/database/TodoDatabaseDriverFactory.kt @@ -3,10 +3,12 @@ package example.todo.common.database import com.squareup.sqldelight.db.SqlDriver import com.squareup.sqldelight.sqlite.driver.JdbcSqliteDriver import example.todo.database.TodoDatabase +import java.io.File @Suppress("FunctionName") // FactoryFunction fun TodoDatabaseDriver(): SqlDriver { - val driver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY) + val databasePath = File(System.getProperty("java.io.tmpdir"), "ComposeTodoDatabase.db") + val driver = JdbcSqliteDriver(url = "jdbc:sqlite:${databasePath.absolutePath}") TodoDatabase.Schema.create(driver) return driver