Setting up the database

Opening a database

Open statement

To open a new database, use

Opening a database
val db ="path/to/db")

By default, Kodein-DB will create the database if it does not exist. If you want to modify this behaviour, you can use:

  • OpenPolicy.Open: fails if the database does not already exist

  • OpenPolicy.Create: fails if the database already exists

Opening an existing database
val db ="path/to/db", OpenPolicy.Open)

Defining the serializer

If you are targeting JVM only, then Kodein-DB will find the serializer by itself, so you don’t need to define it.
However, when targeting Multiplatform, you need to define the KotlinX serializer and the serialized classes manually:

Opening an existing database
val db ="path/to/db",
    KotlinxSerializer { (1)
        +User.serializer() (2)
        +Address.serializer() (2)
1 Registers the KotlinX Serializer.
2 Registers the class and associate serializer.