-
Notifications
You must be signed in to change notification settings - Fork 2
/
VersionsRepo.kt
31 lines (29 loc) · 1.31 KB
/
VersionsRepo.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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<T> : 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 = { _, _ ->}
)
}