Package-level declarations

Types

Link copied to clipboard
sealed class DataResult<out T>

The outcome of a database operation: a value, or the failure that replaced it.

Link copied to clipboard

Hands out queries and sessions, and runs transactions over them.

Link copied to clipboard
internal class OctaviusClientImpl(provider: SessionProvider, onClose: () -> Unit? = null, dynamicJson: Json = octaviusJson, dynamicWriteStrategy: DynamicWriteStrategy = DynamicWriteStrategy.AUTOMATIC_WHEN_UNAMBIGUOUS) : OctaviusClient

The only implementation of OctaviusClient, doing everything through its SessionProvider.

Link copied to clipboard
internal class RollbackSignal(val failure: DataResult.Failure) : RuntimeException

Carries a DataResult.Failure out of a transaction that rolls back only on a throw. Built without a stack trace, since it never reaches the caller.

Functions

Link copied to clipboard
inline fun <T> dbResult(crossinline block: () -> T): DataResult<T>

Runs block and returns what it produced as a DataResult: a failure the application is expected to handle becomes DataResult.Failure, and one that means the calling code is wrong is still thrown.

Link copied to clipboard
inline fun <R, T : R> DataResult<T>.getOrElse(onFailure: (DataResult.Failure) -> R): R

Returns the carried value, or what onFailure makes of the whole DataResult.Failure - which it can return as it is, for an early exit:

Link copied to clipboard
fun <T> DataResult<T>.getOrNull(): T?

Returns the carried value, or null where the operation failed.

Link copied to clipboard

Returns the carried value, or throws the carried failure.

Link copied to clipboard

Whether this failure says the calling code is wrong, so that the result style throws it rather than returning it. Decided by the exception's type, never by its reason.

Link copied to clipboard
inline fun <T, R> DataResult<T>.map(transform: (T) -> R): DataResult<R>

Applies transform to the value of a DataResult.Success, and returns a DataResult.Failure as it stands.

Link copied to clipboard
inline fun <T> DataResult<T>.onFailure(action: (OctaviusException) -> Unit): DataResult<T>

Runs action on the failure if this is a DataResult.Failure, and returns this result either way.

Link copied to clipboard
inline fun <T> DataResult<T>.onSuccess(action: (T) -> Unit): DataResult<T>

Runs action on the carried value if this is a DataResult.Success, and returns this result either way.