KVStore
OCP App SDK / KVStore
Interface: KVStore
Defined in: src/store/KVStore.ts:46
The base interface all key-value stores implement
Extends
Methods
addNumber()
addNumber(
key
,field
,value
):Promise
<boolean
>
Defined in: src/store/KVStore.ts:240
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.
Parameters
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
addNumberMulti()
addNumberMulti(
key
,fieldValues
):Promise
<MultiValue
<NumberSet
>>
Defined in: src/store/KVStore.ts:251
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.
Parameters
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)
addString()
addString(
key
,field
,value
):Promise
<boolean
>
Defined in: src/store/KVStore.ts:305
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.
Parameters
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
addStringMulti()
addStringMulti(
key
,fieldValues
):Promise
<MultiValue
<StringSet
>>
Defined in: src/store/KVStore.ts:316
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.
Parameters
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)
append()
append<
T
>(key
,field
,value
):Promise
<void
>
Defined in: src/store/KVStore.ts:216
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.
Type Parameters
T
T
extends Value
Parameters
key
string
of the stored object
field
string
that holds the list
value
T
to append
Returns
Promise
<void
>
Async
appendMulti()
appendMulti<
T
>(key
,fieldValues
):Promise
<void
>
Defined in: src/store/KVStore.ts:226
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.
Type Parameters
T
T
extends Value
Parameters
key
string
of the stored object
fieldValues
MultiValue
<T
[]>
hash of fields to array of values to append
Returns
Promise
<void
>
Async
delete()
delete<
T
>(key
,fields?
):Promise
<T
>
Defined in: src/store/KVStore.ts:102
Delete an object or a single field from the store at a given key.
If fields is undefined, the entire object will be deleted.
Type Parameters
T
T
extends KVHash
Parameters
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.
Async
Overrides
exists()
exists(
key
):Promise
<boolean
>
Defined in: src/store/KVStore.ts:110
Check if an object exists at a given key.
Parameters
key
string
of the stored object
Returns
Promise
<boolean
>
true if the object exists
Async
Overrides
get()
get<
T
>(key
,fields?
):Promise
<T
>
Defined in: src/store/KVStore.ts:59
Retrieve an object from the store given a key.
Type Parameters
T
T
extends KVHash
Parameters
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.
Async
Overrides
hasNumber()
hasNumber(
key
,field
,value
):Promise
<boolean
>
Defined in: src/store/KVStore.ts:282
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.
Parameters
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
hasNumberMulti()
hasNumberMulti(
key
,fieldValues
):Promise
<MultiValue
<NumberSet
>>
Defined in: src/store/KVStore.ts:291
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.
Parameters
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
hasString()
hasString(
key
,field
,value
):Promise
<boolean
>
Defined in: src/store/KVStore.ts:347
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.
Parameters
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
hasStringMulti()
hasStringMulti(
key
,fieldValues
):Promise
<MultiValue
<StringSet
>>
Defined in: src/store/KVStore.ts:356
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.
Parameters
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
increment()
increment(
key
,field
,amount?
,options?
):Promise
<number
>
Defined in: src/store/KVStore.ts:127
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.
Parameters
key
string
of the stored object
field
string
to increment
amount?
number
by which to increment (can be negative, defaults to 1)
options?
optionally set a TTL for this row
Returns
Promise
<number
>
the value of the field after incrementing
Async
incrementMulti()
incrementMulti(
key
,fieldAmounts
,options?
):Promise
<MultiValue
<number
>>
Defined in: src/store/KVStore.ts:139
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.
Parameters
key
string
of the stored object
fieldAmounts
MultiValue
<number
>
hash of fields to amounts by which to increment (can be negative)
options?
optionally set a TTL for this row
Returns
Promise
<MultiValue
<number
>>
hash of fields to values after incrementing
Async
patch()
Call Signature
patch<
T
>(key
,value
,options?
):Promise
<T
>
Defined in: src/store/KVStore.ts:80
Write a set of fields to an object in the store at a given key. Does not overwrite the entire object.
Type Parameters
T
T
extends KVHash
Parameters
key
string
of the stored object
value
T
hash of fields and values to update the object with. Leaves all other fields untouched.
options?
optionally set a TTL for this row
Returns
Promise
<T
>
the complete object from before the update
An empty object is returned if the object previously did not exist.
Async
Overrides
Call Signature
patch<
T
>(key
,updater
,options?
):Promise
<T
>
Defined in: src/store/KVStore.ts:92
Update a stored object using a callback to make changes.
Type Parameters
T
T
extends KVHash
Parameters
key
string
of the stored object
updater
function to manipulate the existing object (may be called multiple times to ensure an atomic change)
options?
optionally set a TTL for this row
Returns
Promise
<T
>
the complete object from before the update
An empty object is returned if the object previously did not exist.
Async
Overrides
peek()
peek<
T
>(key
,field
):Promise
<undefined
|T
>
Defined in: src/store/KVStore.ts:196
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
.
Type Parameters
T
T
extends Value
Parameters
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
Async
peekMulti()
peekMulti<
T
>(key
,fieldCounts
):Promise
<MultiValue
<T
[]>>
Defined in: src/store/KVStore.ts:206
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.
Type Parameters
T
T
extends Value
Parameters
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
Async
put()
put<
T
>(key
,value
,options?
):Promise
<T
>
Defined in: src/store/KVStore.ts:69
Write an object to the store at a given key. Overwrites the entire object.
Type Parameters
T
T
extends KVHash
Parameters
key
string
of the stored object
value
T
complete hash to write
options?
optionally set a TTL for this row
Returns
Promise
<T
>
the previous value found at the key if successful. Otherwise throws an error.
Async
Overrides
removeNumber()
removeNumber(
key
,field
,value
):Promise
<boolean
>
Defined in: src/store/KVStore.ts:261
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.
Parameters
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
removeNumberMulti()
removeNumberMulti(
key
,fieldValues
):Promise
<MultiValue
<NumberSet
>>
Defined in: src/store/KVStore.ts:272
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.
Parameters
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)
removeString()
removeString(
key
,field
,value
):Promise
<boolean
>
Defined in: src/store/KVStore.ts:326
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.
Parameters
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
removeStringMulti()
removeStringMulti(
key
,fieldValues
):Promise
<MultiValue
<StringSet
>>
Defined in: src/store/KVStore.ts:337
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.
Parameters
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)
shift()
shift<
T
>(key
,field
):Promise
<undefined
|T
>
Defined in: src/store/KVStore.ts:154
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.
Type Parameters
T
T
extends Value
Parameters
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
Async
shiftMulti()
shiftMulti<
T
>(key
,fieldCounts
):Promise
<MultiValue
<T
[]>>
Defined in: src/store/KVStore.ts:166
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.
Type Parameters
T
T
extends Value
Parameters
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
Async
unshift()
unshift<
T
>(key
,field
,value
):Promise
<void
>
Defined in: src/store/KVStore.ts:176
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.
Type Parameters
T
T
extends Value
Parameters
key
string
of the stored object
field
string
that holds the list
value
T
to insert
Returns
Promise
<void
>
Async
unshiftMulti()
unshiftMulti<
T
>(key
,fieldValues
):Promise
<void
>
Defined in: src/store/KVStore.ts:186
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.
Type Parameters
T
T
extends Value
Parameters
key
string
of the stored object
fieldValues
MultiValue
<T
[]>
hash of fields to array of values to insert
Returns
Promise
<void
>
Async
Updated 3 days ago