kotlin-datastore / org.khanacademy.datastore / Datastore

Datastore

class Datastore

Main implementation for interacting with the datastore.

This is the interface for the DB object that represents the external-facing API of this library, though most of the API is implemented as extension functions on this type, above.

This tracks the context of what transaction (if any) we're currently working in so that we can assign async operations to the correct transaction.

TODO(colin): It does not appear that Transaction objects are safe for concurrent use by multiple threads for put operations, so we'll need to synchronize those operations. TODO(colin): more carefully verify this thread-safety behavior.

Properties

coroutineContext

val coroutineContext: <ERROR CLASS>

Extension Functions

get

fun <T : Keyed<T>> Datastore.get(key: Key<T>): T?

Synchronous get by key of an object from the datastore.

getAsync

fun <T : Keyed<T>> Datastore.getAsync(key: Key<T>): <ERROR CLASS><T?>

Asynchronous get by key of an object from the datastore.

inTransaction

fun Datastore.inTransaction(): Boolean

put

fun <T : Keyed<T>> Datastore.put(modelInstance: Keyed<T>): Key<T>

Synchronous put of an object to the datastore.

putAsync

fun <T : Keyed<T>> Datastore.putAsync(modelInstance: Keyed<T>): <ERROR CLASS><Key<T>>

Asynchronous put of an object to the datastore.

transactional

fun <T> Datastore.transactional(options: TransactionOptions, block: Datastore.() -> T): T

Run a function, with all contained datastore operations transactional.

fun <T> Datastore.transactional(block: Datastore.() -> T): T

Run datastore operations in a transaction with default options.