Umesh Gupta
05/29/2025, 12:52 PMroom
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 WasmVidmantas Kerbelis
05/30/2025, 6:19 AMnonJs
source set:
applyDefaultHierarchyTemplate {
common {
group("nonJs") {
withAndroidTarget()
group("ios") {
withIos()
}
}
}
}
• Add Room dependencies to the nonJsMain source:
val nonJsMain by getting {
dependencies {
// Add room + Bundled sqlite here
}
}
• Add whatever else you need for sqldelight to js / wasm: sources:
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:
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
.