All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.dev.inmo.micro_utils.repos.versions.VersionsRepo.kt Maven / Gradle / Ivy

There is a newer version: 0.22.2
Show newest version
package dev.inmo.micro_utils.repos.versions

import dev.inmo.micro_utils.repos.Repo

/**
 * This interface has been created due to requirement to work with different versions of databases and make some
 * migrations between versions
 *
 * @param T It is a type of database, which will be used by this repo to retrieve current table version and update it
 */
interface VersionsRepo : Repo {
    /**
     * By default, instance of this interface will check that version of table with name [tableName] is less than
     * [version] or is absent
     *
     * In case if [tableName] didn't found, will be called [onCreate]. Then in case if [tableName] have version less
     * than parameter [version] or null, it will increase version one-by-one until database version will be equal to
     * [version]
     *
     * @param version Current version of table
     * @param onCreate This callback will be called in case when repo have no information about table
     * @param onUpdate This callback will be called after **iterative** changing of version. It is expected that parameter
     * "to" will always be greater than "from"
     */
    suspend fun setTableVersion(
        tableName: String,
        version: Int,
        onCreate: suspend T.() -> Unit = {},
        onUpdate: suspend T.(from: Int, to: Int) -> Unit = { _, _ ->}
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy