https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Alexander Black

01/18/2023, 10:58 PM
Hey, wondering if anyone has tried using Koin with SQLDelight JS here. The problem I’m running into is
Copy code
initSqlDriver(SomeDb.Schema)
is either a promise or a coroutine on the JS implementation, and thus is not synchronous, and I need the db at the launch of my code. JS doesn’t have a runBlocking method so there’s no easy way I’ve seen to run this synchronously. And if I wanted to create a koin module single { } for this resource the only way I could do it is by returning a Deferred type. The problem with that is a.) I’d have to update a lot of code. b.) I don’t think that resource would be cached, so it’d end up being like a factory {}, because every time I request that resource I’d have to do a await() call on it, which would just call the initSqlDriver(SomeDb.Schema) function again I believe. Does anyone have any tips or suggestions on how I can solve this?
d

Derek Ellis

01/18/2023, 11:02 PM
The approach that I recommend is to wrap your database in a class like the
SharedDatabase
class here in the docs. The class is Koin-friendly and to use the database you can access the database through the
withDatabase
method on the class.
a

Alexander Black

01/18/2023, 11:04 PM
@Derek Ellis Somehow I missed that! Thank you so much! I’m going to give it a shot.
25 Views