tuweni / org.apache.tuweni.kv / SQLKeyValueStore

SQLKeyValueStore

class SQLKeyValueStore<K, V> : KeyValueStore<K, V> (source)

A key-value store backed by a relational database.

Parameters

jdbcurl - The JDBC url to connect to the database.

tableName - the name of the table to use for storage.

keyColumn - the key column of the store.

valueColumn - the value column of the store.

coroutineContext - The co-routine context for blocking tasks.

Exceptions

IOException - If an I/O error occurs.

Return
A key-value store.

Constructors

<init>

Open a relational database backed key-value store.

SQLKeyValueStore(jdbcurl: String, tableName: String = "store", keyColumn: String = "key", valueColumn: String = "value", keySerializer: (K) -> Bytes, valueSerializer: (V) -> Bytes, keyDeserializer: (Bytes) -> K, valueDeserializer: (Bytes?) -> V?, coroutineContext: CoroutineContext = Dispatchers.IO)

Properties

coroutineContext

The co-routine context for blocking tasks.

val coroutineContext: CoroutineContext

keyColumn

the key column of the store.

val keyColumn: String

tableName

the name of the table to use for storage.

val tableName: String

valueColumn

the value column of the store.

val valueColumn: String

Functions

clear

Clears the contents of the store.

suspend fun clear(): Unit

close

Closes the underlying connection pool.

fun close(): Unit

containsKey

Returns true if the store contains the key.

suspend fun containsKey(key: K): Boolean

get

Retrieves data from the store.

suspend fun get(key: K): V?

keys

Provides an iterator over the keys of the store.

suspend fun keys(): Iterable<K>

put

Puts data into the store.

suspend fun put(key: K, value: V): Unit

Companion Object Functions

open

Open a relational database backed key-value store.

fun <K, V> open(jdbcUrl: String, keySerializer: (K) -> Bytes, valueSerializer: (V) -> Bytes, keyDeserializer: (Bytes) -> K, valueDeserializer: (Bytes?) -> V?): SQLKeyValueStore<K, V>
fun <K, V> open(jdbcUrl: String, tableName: String, keyColumn: String, valueColumn: String, keySerializer: (K) -> Bytes, valueSerializer: (V) -> Bytes, keyDeserializer: (Bytes) -> K, valueDeserializer: (Bytes?) -> V?): SQLKeyValueStore<K, V>