Hello, I want to use `room` android, ios and deskt...
# room
u
Hello, I want to use
room
android, ios and desktop but
app.cash.sqldelight
for JS and Wasm . Need help with gradle how to handle NonJs and Js with ksp and room for nonJs and sqldelight {databases {}} for Js and Wasm
v
• Create a
nonJs
source set:
Copy code
applyDefaultHierarchyTemplate {
        common {
            group("nonJs") {
                withAndroidTarget()
                group("ios") {
                    withIos()
                }
            }
        }
    }
• Add Room dependencies to the nonJsMain source:
Copy code
val nonJsMain by getting {
    dependencies {
        // Add room + Bundled sqlite here
    }
}
• Add whatever else you need for sqldelight to js / wasm: sources:
Copy code
jsMain.dependencies { ... }
OR
wasmJsMain.dependencies { ... }

// You can also probably create a shared JS source for js + wasmJs, dunno, not needed in my project, as I'm only on wasmJs
• Create your
abstract class YourDatabase: RoomDatabase
with
@ConstructedBy(YourDatabaseConstructor::class)
in the
nonJs
source set • Create the appropriate SQLDelight implementation in wasmJs / js source set • Personally - my
YourDatabase
exposes all `Dao`'s. The Wasm implementation also exposes all of the same Dao's and I have a wrapper called
CommonDatabase
in
commonMain
which has expect constructors for
wasm
/
nonJs
. • All of the `Dao`'s are `expect interface:
Copy code
expect interface FooDao {
    suspend fun getFoo(): FooDb?
}
Which has actual implementations in wasmJs / nonJs. ---- Kind of that's it - you have two different technologies on the relevant platforms, but in shared code you always use the expect / actual Dao's accessible via
CommonDatabase
.
🙌 2