Extracted createSqliteDriver()

This commit is contained in:
dankito 2024-09-12 00:22:22 +02:00
parent 3a39c0e64f
commit ad4c78a380
1 changed files with 17 additions and 10 deletions

View File

@ -7,6 +7,7 @@ import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.*
import app.cash.sqldelight.async.coroutines.synchronous
import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver
import bankmeister.composeapp.generated.resources.AppIcon_svg
import bankmeister.composeapp.generated.resources.Res
@ -26,8 +27,16 @@ fun main() = application {
icon = painterResource(Res.drawable.AppIcon_svg),
state = WindowState(position = WindowPosition(Alignment.Center), size = DpSize(1000.dp, 800.dp)),
) {
DI.setRepository(createSqlDriverDriver())
App()
}
}
private fun createSqlDriverDriver(): SqlDriver {
File("data/db").mkdirs()
DI.setRepository(JdbcSqliteDriver("jdbc:sqlite:data/db/Bankmeister.db").also { driver ->
return JdbcSqliteDriver("jdbc:sqlite:data/db/Bankmeister.db").also { driver ->
BankmeisterDb.Schema.synchronous().also { schema ->
if (File("data/db/Bankmeister.db").exists() == false) {
schema.create(driver)
@ -35,11 +44,9 @@ fun main() = application {
schema.migrate(driver, schema.version, 1)
}
})
}
}
App()
}
}
@Preview
@Composable