KVStore
OCP App SDK / KVStore
KVStore
The base interface all key-value stores implement
Hierarchy
BaseKVStore
<KVHash
,KVHash
>.KVStore
Index
Methods
- addNumber
- addNumberMulti
- addString
- addStringMulti
- append
- appendMulti
- delete
- exists
- get
- hasNumber
- hasNumberMulti
- hasString
- hasStringMulti
- increment
- incrementMulti
- patch
- peek
- peekMulti
- put
- removeNumber
- removeNumberMulti
- removeString
- removeStringMulti
- shift
- shiftMulti
- unshift
- unshiftMulti
Methods
addNumber()
Atomically adds a value to a NumberSet. If the object or field does not exist, it will be created with a NumberSet
containing the given element. If the field exists but is not a NumberSet, this will result in an error.
Signature
addNumber(key: string, field: string, value: number): Promise<boolean>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
field | string | that holds the NumberSet |
value | number | to add |
Returns
Promise
<boolean
>
true
if the value was newly added, false
if it was already a member of the set
Defined in: src/store/KVStore.ts:236
addNumberMulti()
Atomically adds the given arrays of values to the given NumberSet fields. If the object or fields do not exist,
they will be created from the given arrays. If any field exists but is not a NumberSet, this will result in an
error.
Signature
addNumberMulti(key: string, fieldValues: MultiValue<number[]>): Promise<MultiValue<NumberSet>>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
fieldValues | MultiValue <number []> | hash of fields to array of values to add |
Returns
Promise
<MultiValue
<NumberSet
>>
hash of fields to NumberSet containing only the values that were newly added (any values that already
existed in the target NumberSet will not exist in the return value)
Defined in: src/store/KVStore.ts:247
addString()
Atomically adds a value to a StringSet. If the object or field does not exist, it will be created with a StringSet
containing the given element. If the field exists but is not a StringSet, this will result in an error.
Signature
addString(key: string, field: string, value: string): Promise<boolean>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
field | string | that holds the StringSet |
value | string | to add |
Returns
Promise
<boolean
>
true
if the value was newly added, false
if it was already a member of the set
Defined in: src/store/KVStore.ts:301
addStringMulti()
Atomically adds the given arrays of values to the given StringSet fields. If the object or fields do not exist,
they will be created from the given arrays. If any field exists but is not a StringSet, this will result in an
error.
Signature
addStringMulti(key: string, fieldValues: MultiValue<string[]>): Promise<MultiValue<StringSet>>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
fieldValues | MultiValue <string []> | hash of fields to array of values to add |
Returns
Promise
<MultiValue
<StringSet
>>
hash of fields to StringSet containing only the values that were newly added (any values that already
existed in the target StringSet will not exist in the return value)
Defined in: src/store/KVStore.ts:312
append()
Atomically append an element to the end of a list. If the object or field does not exist, it will be created
with a list consisting of the given element. If the field exists but is not a list, this will result in an error.
Async
Signature
append<T>(key: string, field: string, value: T): Promise<void>;
Type parameters
T
extendsValue
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
field | string | that holds the list |
value | T | to append |
Returns
Promise
<void
>
Defined in: src/store/KVStore.ts:212
appendMulti()
Atomically append the given arrays of elements to the end of the given lists. If the object or fields do not
exist, they will be created from the given arrays. If any field exists but is not a list, this will result in an
error.
Async
Signature
appendMulti<T>(key: string, fieldValues: MultiValue<T[]>): Promise<void>;
Type parameters
T
extendsValue
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
fieldValues | MultiValue <T []> | hash of fields to array of values to append |
Returns
Promise
<void
>
Defined in: src/store/KVStore.ts:222
delete()
Delete an object or a single field from the store at a given key.
If fields is undefined, the entire object will be deleted.
Async
Signature
delete<T>(key: string, fields?: string[]): Promise<T>;
Type parameters
T
extendsKVHash
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
fields? | string [] | to delete or undefined to delete all fields |
Returns
Promise
<T
>
the deleted value if successful, or an empty object if it did not exist.
Overrides: BaseKVStore.delete
Defined in: src/store/KVStore.ts:100
exists()
Check if an object exists at a given key.
Async
Signature
exists(key: string): Promise<boolean>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
Returns
Promise
<boolean
>
true if the object exists
Overrides: BaseKVStore.exists
Defined in: src/store/KVStore.ts:108
get()
Retrieve an object from the store given a key.
Async
Signature
get<T>(key: string, fields?: string[]): Promise<T>;
Type parameters
T
extendsKVHash
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
fields? | string [] | to retrieve from the stored object, or undefined to retrieve the full object |
Returns
Promise
<T
>
hash of the complete object or only the specified fields, if supplied.
An empty object is returned if the object, or all specified fields, does not exist.
Overrides: BaseKVStore.get
Defined in: src/store/KVStore.ts:59
hasNumber()
Checks if a value exists in a NumberSet. Calling this method on a non-existent object will not cause it to be
created. If the field exists but is not a NumberSet, this will result in an error.
Signature
hasNumber(key: string, field: string, value: number): Promise<boolean>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
field | string | that holds the NumberSet |
value | number | to check |
Returns
Promise
<boolean
>
true
if the value is a member of the set, false
if it is not
Defined in: src/store/KVStore.ts:278
hasNumberMulti()
Checks if the given arrays of values exist in the given NumberSet fields. Calling this method on a non-existent
object will not cause it to be created. If any field exists but is not a NumberSet, this will result in an error.
Signature
hasNumberMulti(key: string, fieldValues: MultiValue<number[]>): Promise<MultiValue<NumberSet>>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
fieldValues | MultiValue <number []> | hash of fields to array of values to check |
Returns
Promise
<MultiValue
<NumberSet
>>
hash of fields to NumberSet containing only the values that exist in the target NumberSet
Defined in: src/store/KVStore.ts:287
hasString()
Checks if a value exists in a StringSet. Calling this method on a non-existent object will not cause it to be
created. If the field exists but is not a StringSet, this will result in an error.
Signature
hasString(key: string, field: string, value: string): Promise<boolean>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
field | string | that holds the StringSet |
value | string | to check |
Returns
Promise
<boolean
>
true
if the value is a member of the set, false
if it is not
Defined in: src/store/KVStore.ts:343
hasStringMulti()
Checks if the given arrays of values exist in the given StringSet fields. Calling this method on a non-existent
object will not cause it to be created. If any field exists but is not a StringSet, this will result in an error.
Signature
hasStringMulti(key: string, fieldValues: MultiValue<string[]>): Promise<MultiValue<StringSet>>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
fieldValues | MultiValue <string []> | hash of fields to array of values to check |
Returns
Promise
<MultiValue
<StringSet
>>
hash of fields to StringSet containing only the values that exist in the target StringSet
Defined in: src/store/KVStore.ts:352
increment()
Atomically increment the value of a numeric field. If the object or field did not previously exist, the resulting
field will be set to the given amount. If the field does already exist but is not a number, this will result in
an error.
Async
Signature
increment(key: string, field: string, amount?: number): Promise<number>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
field | string | to increment |
amount? | number | by which to increment (can be negative, defaults to 1) |
Returns
Promise
<number
>
the value of the field after incrementing
Defined in: src/store/KVStore.ts:124
incrementMulti()
Atomically increment the values of multiple numeric fields. If the object or fields did not previously exist, the
resulting fields will be set to their respective given amount. If any of the fields does already exist but is not a
number, this will result in an error.
Async
Signature
incrementMulti(key: string, fieldAmounts: MultiValue<number>): Promise<MultiValue<number>>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
fieldAmounts | MultiValue <number > | hash of fields to amounts by which to increment (can be negative) |
Returns
Promise
<MultiValue
<number
>>
hash of fields to values after incrementing
Defined in: src/store/KVStore.ts:135
patch()
Write a set of fields to an object in the store at a given key. Does not overwrite the entire object.
Async
Signature
patch<T>(key: string, value: T): Promise<T>;
Type parameters
T
extendsKVHash
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
value | T | hash of fields and values to update the object with. Leaves all other fields untouched. |
Returns
Promise
<T
>
the complete object from before the update
An empty object is returned if the object previously did not exist.
Overrides: BaseKVStore.patch
Defined in: src/store/KVStore.ts:79
Update a stored object using a callback to make changes.
Async
Signature
patch<T>(key: string, updater: KVPatchUpdater<T>): Promise<T>;
Type parameters
T
extendsKVHash
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
updater | KVPatchUpdater <T > | function to manipulate the existing object (may be called multiple times to ensure an atomic change) |
Returns
Promise
<T
>
the complete object from before the update
An empty object is returned if the object previously did not exist.
Overrides: BaseKVStore.patch
Defined in: src/store/KVStore.ts:90
peek()
Retrieve (without removing) the first element from a list. If the object or field does not exist, is empty, or is
not a list, the result will be undefined
.
Async
Signature
peek<T>(key: string, field: string): Promise<undefined | T>;
Type parameters
T
extendsValue
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
field | string | that holds the list |
Returns
Promise
<undefined
| T
>
the first element of the list, if available, otherwise undefined
Defined in: src/store/KVStore.ts:192
peekMulti()
Retrieve (without removing) up to the given number of elements from the front of the given lists. If the object
or fields do not exist, are empty, or are not lists, the result of each missing field will be an empty array.
Async
Signature
peekMulti<T>(key: string, fieldCounts: MultiValue<number>): Promise<MultiValue<T[]>>;
Type parameters
T
extendsValue
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
fieldCounts | MultiValue <number > | hash of fields to number of elements to retrieve |
Returns
Promise
<MultiValue
<T
[]>>
hash of fields to array of list elements
Defined in: src/store/KVStore.ts:202
put()
Write an object to the store at a given key. Overwrites the entire object.
Async
Signature
put<T>(key: string, value: T, options?: KVRowOptions): Promise<T>;
Type parameters
T
extendsKVHash
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
value | T | complete hash to write |
options? | KVRowOptions | optionally set a TTL for this row |
Returns
Promise
<T
>
the previous value found at the key if successful. Otherwise throws an error.
Overrides: BaseKVStore.put
Defined in: src/store/KVStore.ts:69
removeNumber()
Atomically removes a value from a NumberSet. Calling this method on a non-existent object will not cause it to
be created. If the field exists but is not a NumberSet, this will result in an error.
Signature
removeNumber(key: string, field: string, value: number): Promise<boolean>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
field | string | that holds the NumberSet |
value | number | to remove |
Returns
Promise
<boolean
>
true
if the value was removed, false
if it was not a member of the set
Defined in: src/store/KVStore.ts:257
removeNumberMulti()
Atomically removes the given arrays of values from the given NumberSet fields. Calling this method on a
non-existent object will not cause it to be created. If any field exists but is not a NumberSet, this will result
in an error.
Signature
removeNumberMulti(key: string, fieldValues: MultiValue<number[]>): Promise<MultiValue<NumberSet>>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
fieldValues | MultiValue <number []> | hash of fields to array of values to remove |
Returns
Promise
<MultiValue
<NumberSet
>>
hash of fields to NumberSet containing only the values that were removed (any values that did not exist in
the target NumberSet will not exist in the return value)
Defined in: src/store/KVStore.ts:268
removeString()
Atomically removes a value from a StringSet. Calling this method on a non-existent object will not cause it to
be created. If the field exists but is not a StringSet, this will result in an error.
Signature
removeString(key: string, field: string, value: string): Promise<boolean>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
field | string | that holds the StringSet |
value | string | to remove |
Returns
Promise
<boolean
>
true
if the value was removed, false
if it was not a member of the set
Defined in: src/store/KVStore.ts:322
removeStringMulti()
Atomically removes the given arrays of values from the given StringSet fields. Calling this method on a
non-existent object will not cause it to be created. If any field exists but is not a StringSet, this will result
in an error.
Signature
removeStringMulti(key: string, fieldValues: MultiValue<string[]>): Promise<MultiValue<StringSet>>;
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
fieldValues | MultiValue <string []> | hash of fields to array of values to remove |
Returns
Promise
<MultiValue
<StringSet
>>
hash of fields to StringSet containing only the values that were removed (any values that did not exist in
the target StringSet will not exist in the return value)
Defined in: src/store/KVStore.ts:333
shift()
Atomically retrieve and remove the first element from a list. If the object or field does not exist or is empty,
the result will be undefined
. Calling this method on a non-existent object will not cause it to be created. If
the field exists but is not a list, this will result in an error.
Async
Signature
shift<T>(key: string, field: string): Promise<undefined | T>;
Type parameters
T
extendsValue
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
field | string | that holds the list |
Returns
Promise
<undefined
| T
>
the first element of the list, if available, otherwise undefined
Defined in: src/store/KVStore.ts:150
shiftMulti()
Atomically retrieve and remove up to the given number of elements from the front of the given lists. If the
object or fields do not exist or are empty, the result of each missing field will be an empty array. Calling this
method on a non-existent object will not cause it to be created. If any field exists but is not a list, this will
result in an error.
Async
Signature
shiftMulti<T>(key: string, fieldCounts: MultiValue<number>): Promise<MultiValue<T[]>>;
Type parameters
T
extendsValue
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
fieldCounts | MultiValue <number > | hash of fields to number of elements to retrieve and remove |
Returns
Promise
<MultiValue
<T
[]>>
hash of fields to array of list elements
Defined in: src/store/KVStore.ts:162
unshift()
Atomically insert an element at the front of a list. If the object or field does not exist, it will be created
with a list consisting of the given element. If the field exists but is not a list, this will result in an error.
Async
Signature
unshift<T>(key: string, field: string, value: T): Promise<void>;
Type parameters
T
extendsValue
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
field | string | that holds the list |
value | T | to insert |
Returns
Promise
<void
>
Defined in: src/store/KVStore.ts:172
unshiftMulti()
Atomically insert the given arrays of elements at the front of the given lists. If the object or fields do not
exist, they will be created from the given arrays. If any field exists but is not a list, this will result in an
error.
Async
Signature
unshiftMulti<T>(key: string, fieldValues: MultiValue<T[]>): Promise<void>;
Type parameters
T
extendsValue
Parameters
Name | Type | Description |
---|---|---|
key | string | of the stored object |
fieldValues | MultiValue <T []> | hash of fields to array of values to insert |
Returns
Promise
<void
>
Defined in: src/store/KVStore.ts:182
Updated 2 months ago