migrate(local-db): replace Room with SQLDelight for JS/WASM compatibility
Replaced Room with SQLDelight for improved multiplatform support, enabling JavaScript and WebAssembly targets. Added custom database driver implementations for JVM, JS, and WASM. Updated Gradle configurations, dependencies, and project structure accordingly.
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
package at.mocode.frontend.core.localdb
|
||||
|
||||
import app.cash.sqldelight.db.SqlDriver
|
||||
|
||||
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
|
||||
expect class DatabaseDriverFactory {
|
||||
suspend fun createDriver(): SqlDriver
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
|
||||
|
||||
package at.mocode.frontend.core.localdb
|
||||
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.IO
|
||||
import org.koin.dsl.module
|
||||
|
||||
// Abstract Room Database class definition
|
||||
// @Database(entities = [MyEntity::class], version = 1) // Entities need to be defined
|
||||
abstract class MeldestelleDb : RoomDatabase() {
|
||||
// abstract fun myDao(): MyDao
|
||||
}
|
||||
|
||||
// Factory to create the database builder platform-specifically
|
||||
expect class DatabaseBuilderFactory() {
|
||||
fun create(): RoomDatabase.Builder<MeldestelleDb>
|
||||
}
|
||||
|
||||
class DatabaseProvider(private val factory: DatabaseBuilderFactory) {
|
||||
fun createDatabase(): MeldestelleDb {
|
||||
return factory.create()
|
||||
.setDriver(BundledSQLiteDriver())
|
||||
.setQueryCoroutineContext(Dispatchers.IO)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
val localDbModule = module {
|
||||
single { DatabaseBuilderFactory() }
|
||||
single { DatabaseProvider(get()).createDatabase() }
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
CREATE TABLE Task (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
content TEXT NOT NULL,
|
||||
is_completed INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
selectAll:
|
||||
SELECT *
|
||||
FROM Task;
|
||||
|
||||
insert:
|
||||
INSERT INTO Task(id, content, is_completed)
|
||||
VALUES ?;
|
||||
|
||||
delete:
|
||||
DELETE FROM Task
|
||||
WHERE id = ?;
|
||||
Reference in New Issue
Block a user