Persist exchange rates, selected currencies, and price source via SQLDelight

Adds a SQLDelight-backed AppDatabase (Android, Desktop, iOS/macOS) so the
converter survives restarts: the last-known rates per price source, the
user's selected fiat currencies (with order preserved), and the last-used
price source all reload before the first network fetch completes. Web isn't
a shipped platform and SQLDelight's driver there needs a worker plus a wasm
sqlite binary, so it gets a lighter localStorage-backed implementation of
the same store interfaces instead.

Android needs an app Context for its driver, wired via a new
SatsPriceApplication. iOS/macOS need libsqlite3 linked explicitly (Swift's
autolinking only covers Shared.framework itself, not its C library
dependencies), plus two extension-loading symbols marked optional since
macOS's system sqlite build omits them.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QpjMKWGoiT5aJBzhxvXkwp
This commit is contained in:
2026-09-08 09:34:21 +03:00
co-authored by Claude Sonnet 5
parent 8a73b140c4
commit 14298d450e
20 changed files with 506 additions and 3 deletions
@@ -0,0 +1,20 @@
package xyz.tyiu.satsprice.data.db
import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver
import xyz.tyiu.satsprice.db.AppDatabase
import java.io.File
private val database: AppDatabase by lazy {
val appDir = File(System.getProperty("user.home"), ".sats-price").apply { mkdirs() }
val databaseFile = File(appDir, "sats-price.db")
val isNewDatabase = !databaseFile.exists()
val driver = JdbcSqliteDriver("jdbc:sqlite:${databaseFile.absolutePath}")
if (isNewDatabase) {
AppDatabase.Schema.create(driver)
}
AppDatabase(driver)
}
actual fun createExchangeRateStore(): ExchangeRateStore = SqlDelightExchangeRateStore(database)
actual fun createSelectedCurrenciesStore(): SelectedCurrenciesStore = SqlDelightSelectedCurrenciesStore(database)
actual fun createSelectedSourceStore(): SelectedSourceStore = SqlDelightSelectedSourceStore(database)