Re. `kodein-db`, am calling `val db = DB.open("bik...
# kodein
j
Re.
kodein-db
, am calling
val db = DB.open("bikeshare_db")
but getting
Copy code
org.kodein.db.leveldb.LevelDBException: NotFound: bikeshare_db/LOCK: No such file or directory
it seemed from https://docs.kodein.org/kodein-db/0.2.0/core/setup-database.html that the default is to create the database if it does not exist?
r
This is maybe because you’re not in the app directory. Generally, in KMM projects we bind a DB factory with
Copy code
DB.factory.inDir(getApplicationFilesDirectoryPath(di))
where
getApplicationFilesDirectoryPath
is an expect function
with actual on iOS
Copy code
actual fun getApplicationFilesDirectoryPath(di: DI): String =
    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0] as String
And Android
Copy code
actual fun getApplicationFilesDirectoryPath(di: DI): String =
    di.direct.instance<Context>(tag = "app").filesDir.absolutePath
this code use Kodein-DI but I’m sur you know how to retrieve the app Context 😉
j
thanks, will try that
r
Let us know if you need help. We definitely need to provide better docs and accessible code samples.
j
what is
DI
type above?
r
It’s our Dependency Injection main type, we use it to retrieve the app Context provided by a Kodein-DI module
j
ah, ok
r
you don’t need it
but you’ll need to find a way (with Koin or manually) you get your Context
j
yeah, have same requirement for SQLDelight
r
or even try Kodein-DI 😛
j
@romainbsl would you mind taking a look over following to see if any glaring mistakes https://johnoreilly.dev/posts/kodein-db-multiplatform/
Short one mostly aimed at giving flavour of what library provides along with sample code in the github repo
Will hopefully expand on that when I have time
r
Thanks a lot John. That’s a really nice introduction! 🙂
j
No problem at all....very cool library! BTW my changes to start using it are in master of https://github.com/joreilly/BikeShare now
👍 1