KeyValueStorage

open class KeyValueStorage<T : Any>(entityName: String, entityQueries: EntityQueries, metadataQueries: MetadataQueries, scope: ERROR CLASS: Symbol not found for CoroutineScope, type: KType, serializer: SqkonSerializer = KotlinSqkonSerializer(), config: KeyValueStorage.Config = Config(), readDispatcher: ERROR CLASS: Symbol not found for CoroutineDispatcher, writeDispatcher: ERROR CLASS: Symbol not found for CoroutineDispatcher, transacter: SqkonTransacter) : <ERROR CLASS> ERROR CLASS: Symbol not found for Transacter(source)

Base interaction to the database.

Parameters

serializer

if providing your own, recommend using SqkonJson to make sure you create fields consistently.

Constructors

Link copied to clipboard
constructor(entityName: String, entityQueries: EntityQueries, metadataQueries: MetadataQueries, scope: ERROR CLASS: Symbol not found for CoroutineScope, type: KType, serializer: SqkonSerializer = KotlinSqkonSerializer(), config: KeyValueStorage.Config = Config(), readDispatcher: ERROR CLASS: Symbol not found for CoroutineDispatcher, writeDispatcher: ERROR CLASS: Symbol not found for CoroutineDispatcher, transacter: SqkonTransacter)

Types

Link copied to clipboard
data class Config(val deserializePolicy: KeyValueStorage.Config.DeserializePolicy = DeserializePolicy.ERROR, val dispatcher: ERROR CLASS: Symbol not found for CoroutineDispatcher = Dispatchers.Default)

Functions

Link copied to clipboard
fun count(where: Where<T>? = null, expiresAfter: ERROR CLASS: Symbol not found for Instant?? = null): ERROR CLASS: Symbol not found for Flow<kotlin/Int>
Link copied to clipboard
fun delete(where: Where<T>? = null): ERROR CLASS: Unresolved name: transaction

Delete using where clause. If where is null, all rows will be deleted.

Link copied to clipboard
fun deleteAll(): ERROR CLASS: Unresolved name: transaction

Delete all rows. Basically an alias for delete with no where set.

Link copied to clipboard

Delete by key.

Link copied to clipboard
fun deleteByKeys(vararg key: String): ERROR CLASS: Unresolved name: transaction

Delete by keys.

Link copied to clipboard
fun deleteExpired(expiresAfter: ERROR CLASS: Symbol not found for Instant = Clock.System.now()): ERROR CLASS: Unresolved name: transaction

Purge all rows that have there expired_at field NOT null and less than (<) the date passed in. (Usually Clock.System.now).

Link copied to clipboard
fun deleteStale(writeInstant: ERROR CLASS: Symbol not found for Instant?? = Clock.System.now(), readInstant: ERROR CLASS: Symbol not found for Instant?? = Clock.System.now()): ERROR CLASS: Unresolved name: transaction

Unlike deleteExpired, this will clean up rows that have not been touched (read/written) before the passed in time.

Link copied to clipboard
fun deleteState(instant: ERROR CLASS: Symbol not found for Instant)

Unlike deleteExpired, this will clean up rows that have not been touched (read/written) before the passed in time.

Link copied to clipboard
fun insert(key: String, value: T, ignoreIfExists: Boolean = false, expiresAt: ERROR CLASS: Symbol not found for Instant?? = null): ERROR CLASS: Unresolved name: transaction

Insert a row.

Link copied to clipboard
fun insertAll(values: Map<String, T>, ignoreIfExists: Boolean = false, expiresAt: ERROR CLASS: Symbol not found for Instant?? = null): ERROR CLASS: Unresolved name: transaction

Insert multiple rows.

Link copied to clipboard
fun metadata(): ERROR CLASS: Symbol not found for Flow<com/mercury/sqkon/db/Metadata>

Metadata for the entity, this will tell you the last time the entity store was read and written to, useful for cache invalidation.

Link copied to clipboard
fun select(where: Where<T>? = null, orderBy: List<OrderBy<T>> = emptyList(), limit: Long? = null, offset: Long? = null, expiresAfter: ERROR CLASS: Symbol not found for Instant?? = null): ERROR CLASS: Symbol not found for Flow<kotlin/collections/List<T>>

Select using where clause. If where is null, all rows will be selected.

Link copied to clipboard
fun selectAll(orderBy: List<OrderBy<T>> = emptyList(), expiresAfter: ERROR CLASS: Symbol not found for Instant?? = null): ERROR CLASS: Symbol not found for Flow<kotlin/collections/List<T>>

Select all rows. Effectively an alias for select with no where set.

Link copied to clipboard
fun selectByKey(key: String): ERROR CLASS: Symbol not found for Flow<T?>

Select by key.

Link copied to clipboard
fun selectByKeys(keys: Collection<String>, orderBy: List<OrderBy<T>> = emptyList(), expiresAfter: ERROR CLASS: Symbol not found for Instant?? = null): ERROR CLASS: Symbol not found for Flow<kotlin/collections/List<T>>

Select by keys with optional ordering

Link copied to clipboard
fun selectKeysetPagingSource(pageSize: Int, where: Where<T>? = null, orderBy: List<OrderBy<T>> = emptyList(), expiresAfter: ERROR CLASS: Symbol not found for Instant?? = null): ERROR CLASS: Symbol not found for PagingSource<kotlin/String, T>

Create a PagingSource that pages through results using keyset-based pagination. Unlike selectPagingSource, this avoids the O(n) cost of SQL OFFSET on large datasets by using pre-calculated page boundary keys.

Link copied to clipboard
fun selectPagingSource(where: Where<T>? = null, orderBy: List<OrderBy<T>> = emptyList(), initialOffset: Int = 0, expiresAfter: ERROR CLASS: Symbol not found for Instant?? = null): ERROR CLASS: Symbol not found for PagingSource<kotlin/Int, T>

Create a PagingSource that pages through results according to queries generated by from the passed in where and orderBy. initialOffset initial offset to start paging from.

Link copied to clipboard
fun selectResult(where: Where<T>? = null, orderBy: List<OrderBy<T>> = emptyList(), limit: Long? = null, offset: Long? = null, expiresAfter: ERROR CLASS: Symbol not found for Instant?? = null): ERROR CLASS: Symbol not found for Flow<kotlin/collections/List<com/mercury/sqkon/db/ResultRow<T>>>

Select using where clause. If where is null, all rows will be selected.

Link copied to clipboard
fun update(key: String, value: T, expiresAt: ERROR CLASS: Symbol not found for Instant?? = null): ERROR CLASS: Unresolved name: transaction

Update a row. If the row does not exist, it will update nothing, use insert if you want to insert if the row does not exist.

Link copied to clipboard
fun updateAll(values: Map<String, T>, expiresAt: ERROR CLASS: Symbol not found for Instant?? = null): ERROR CLASS: Unresolved name: transaction

Convenience function to insert collection of rows. If the row does not exist, ti will update nothing, use insert if you want to insert if the row does not exist.

Link copied to clipboard
fun upsert(key: String, value: T, expiresAt: ERROR CLASS: Symbol not found for Instant?? = null): ERROR CLASS: Unresolved name: transaction

Convenience function to insert a new row or update an existing row.

Link copied to clipboard
fun upsertAll(values: Map<String, T>, expiresAt: ERROR CLASS: Symbol not found for Instant?? = null): ERROR CLASS: Unresolved name: transaction

Convenience function to insert new or update existing multiple rows.