Browse Source

Persist desktop database

pull/10/head
Arkadii Ivanov 4 years ago
parent
commit
f6756ef6b7
  1. 2
      examples/todo/common/database/src/commonMain/sqldelight/example/todo/common/database/TodoDatabase.sq
  2. 4
      examples/todo/common/database/src/desktopMain/kotlin/example/todo/common/database/TodoDatabaseDriverFactory.kt

2
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,

4
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

Loading…
Cancel
Save