KandraSuspendRepository

class KandraSuspendRepository<T : Any>(session: CqlSession, schema: TableSchema, entityClass: KClass<T>, batchEngine: BatchEngine)

Coroutine-friendly repository for performing CRUD operations on a ScyllaDB table.

All write operations delegate to BatchEngine (which wraps blocking driver calls); wrap in withContext(Dispatchers.IO) when needed in production.

Parameters

T

the entity type annotated with @ScyllaTable

Constructors

Link copied to clipboard
constructor(session: CqlSession, schema: TableSchema, entityClass: KClass<T>, batchEngine: BatchEngine)

Functions

Link copied to clipboard
suspend fun <V> append(entity: T, field: KProperty1<T, Collection<V>?>, values: Collection<V>, consistency: KandraConsistency? = null)
Link copied to clipboard
suspend fun decrement(field: KProperty1<T, Long?>, partitionKeys: Map<String, Any>, by: Long = 1, consistency: KandraConsistency? = null)
Link copied to clipboard
suspend fun delete(entity: T)
Link copied to clipboard
suspend fun deleteAll(entities: List<T>)
Link copied to clipboard
suspend fun deleteBy(block: QueryContext.() -> Unit)
Link copied to clipboard
suspend fun deleteById(vararg keyValues: Any)
Link copied to clipboard
suspend fun exists(consistency: KandraConsistency? = null, block: QueryContext.() -> Unit): Boolean
Link copied to clipboard
suspend fun find(consistency: KandraConsistency? = null, block: QueryContext.() -> Unit): T?
Link copied to clipboard
suspend fun findActive(allowFullScan: Boolean = false): List<T>

Returns all rows not yet soft-deleted. Requires @SoftDelete(markerProperty = "...") on T — throws KandraSchemaException otherwise.

Link copied to clipboard
suspend fun findAll(limit: Int? = null, consistency: KandraConsistency? = null, block: QueryContext.() -> Unit): List<T>
Link copied to clipboard
suspend fun findById(vararg idValues: Any, consistency: KandraConsistency? = null): T?
Link copied to clipboard
suspend fun findPage(pageSize: Int, pageToken: String? = null, consistency: KandraConsistency? = null, block: QueryContext.() -> Unit = {}): KandraPage<T>
Link copied to clipboard
suspend fun increment(field: KProperty1<T, Long?>, partitionKeys: Map<String, Any>, by: Long = 1, consistency: KandraConsistency? = null)
Link copied to clipboard
suspend fun <K, V> put(entity: T, field: KProperty1<T, Map<K, V>?>, entries: Map<K, V>, consistency: KandraConsistency? = null)
Link copied to clipboard
suspend fun raw(cql: String, vararg params: Any?): List<Row>
Link copied to clipboard
suspend fun rawQuery(query: KandraRawQuery): List<Row>
Link copied to clipboard
suspend fun <V> remove(entity: T, field: KProperty1<T, Collection<V>?>, values: Collection<V>, consistency: KandraConsistency? = null)
Link copied to clipboard
suspend fun save(entity: T, ttlSeconds: Int? = null, timestampMicros: Long? = null, consistency: KandraConsistency? = null)
Link copied to clipboard
suspend fun saveAll(entities: List<T>, useBatch: Boolean = true, consistency: KandraConsistency? = null)
Link copied to clipboard
suspend fun saveAndGet(entity: T, ttlSeconds: Int? = null, timestampMicros: Long? = null, consistency: KandraConsistency? = null): T

Same write as save, but returns the entity actually persisted — including any @GeneratedUuid/@CreatedAt/@UpdatedAt/@Version values generated for the write, which save computes internally and then discards. Use this whenever the caller needs those generated values (e.g. to build an HTTP response) instead of the placeholder ones on the object it constructed — see GH #132 / ISS-096.

Link copied to clipboard
suspend fun saveIfNotExists(entity: T, serialConsistency: KandraConsistency = KandraConsistency.LOCAL_SERIAL): Boolean
Link copied to clipboard
suspend fun saveIfNotExistsAndGet(entity: T, serialConsistency: KandraConsistency = KandraConsistency.LOCAL_SERIAL): T?

Same LWT write as saveIfNotExists, but returns the entity actually persisted — including any @GeneratedUuid/@CreatedAt/@UpdatedAt values generated for the write, which saveIfNotExists computes internally and then discards behind a bare Boolean. Returns null when the row already existed (the same case saveIfNotExists reports as false). See KandraRepository.saveIfNotExistsAndGet's doc (the blocking counterpart) — GH #138.

Link copied to clipboard
suspend fun saveWithNulls(entity: T, ttlSeconds: Int? = null, consistency: KandraConsistency? = null)
Link copied to clipboard
suspend fun update(old: T, new: T, consistency: KandraConsistency? = null, ttlSeconds: Int? = null, serialConsistency: KandraConsistency = KandraConsistency.LOCAL_SERIAL)

Optimistic-locked update: UPDATE ... IF <version> = ? when the entity has an @Version column (otherwise a blind full-row overwrite — see the kandra-runtime skill doc).

Link copied to clipboard
suspend fun updateAndGet(old: T, new: T, consistency: KandraConsistency? = null, ttlSeconds: Int? = null, serialConsistency: KandraConsistency = KandraConsistency.LOCAL_SERIAL): T

Same write as update, but returns the entity actually persisted — including the post-update @Version (and @UpdatedAt) values update computes internally and then discards. Use this whenever the caller needs those generated values, e.g. to make a subsequent optimistic-locked update()/updateAndGet() call against the same row without risking a spurious io.kandra.core.exception.KandraOptimisticLockException from reusing the stale pre-update version it already had — see GH #136.

Link copied to clipboard
suspend fun updateForce(entity: T, consistency: KandraConsistency? = null)