Sqkon (/sk-on/) A Kotlin Multiplatform KeyValue Store with the ability to query on values using SQLite and JSONB.
// Create a new instance of Sqkon
val sqkon = Sqkon(
context = context // (only for Android)
)
// Create a Store for each type/entity you want to create
val merchantStore = sqkon.keyValueStore<Merchant>("merchant")
// Insert a new entity
val merchant = Merchant(
id = MerchantKey("1"),
name = "Chipotle",
category = "Food"
)
// Insert, similar to a SQL INSERT, no table definition needed.
merchantStore.insert(key = merchant.id.value, value = merchant)
// Query on any field
val flow: Flow<List<Merchant>> = merchantStore.select(where = Merchant::name like "Chi%")
// Example entity
@Serializable
data class Merchant(
val id: MerchantKey,
val name: String,
val category: String,
)
Multiplatform projects (Android, JVM, iOS (coming soon))
commonMain {
dependencies {
implementation("com.mercury.sqkon:library:1.0.0-alpha01")
}
}
Or you can use the platform specific dependencies, e.g: Android only:
dependencies {
implementation("com.mercury.sqkon:library-android:1.0.0-alpha01")
}
The project is built upon SQLDelight and kotlinx.serialization, these are transitive dependencies, but you will not be able to use the library with applying the kotlinx-serialization plugin. If you are not using kotlinx serialization, I suggest you read about it here: https://github.com/Kotlin/kotlinx.serialization.
Sqkon doesn't provide default cache busting out of the box, but it does provide the tools to do this if that's what you require.
KeyValueStore.selectResult
will expose a ResultRow with aexpiresAt
,writeAt
andreadAt
fields, with this you can handle cache busting yourself.- Most methods support
expiresAt
,expiresAfter
which let you set expiry times, we don't auto purge fields that have "expired" use usedeleteExpired
to remove them. We trackreadAt
,writeAt
when rows are read/written too. - We provide
deleteWhere
,deleteExpired
,deleteStale
, the docs explain there differences.
- Run
./gradlew :core:assembleRelease
- Run
./gradlew :core:jvmJar