- Since:
- 3.0
Members
(nullable) key :string
Returns the key of the data node represented by this ServerlessDb.ServerlessDbNode
or null
if this instance
represents the root node of the database.
Type:
- string
(nullable) parent :ServerlessDb.ServerlessDbNode
Returns the parent node of this ServerlessDb.ServerlessDbNode
in the database or null
if this instance represents
the root node.
Type:
path :string
Returns the path of the data node represented by this ServerlessDb.ServerlessDbNode
as a slash-separated string.
Type:
- string
timestamp :Date
Gets the timestamp encoded within the key
of this ServerlessDb.ServerlessDbNode
, when it
has been generated using the ServerlessDb#generateUniqueKey
or ServerlessDb.ServerlessDbNode#push
methods.
If the key of this node has not been generated using one of these methods, the value of this property is meaningless.
Type:
- Date
Methods
cancelNextDisconnectionOps() → {Promise}
Cancels all write operations on the path of this ServerlessDb.ServerlessDbNode
previously scheduled
(using one of the ServerlessDb.ServerlessDbNode#clear
, ServerlessDb.ServerlessDbNode#set
or ServerlessDb.ServerlessDbNode#merge
methods) at next disconnection of the
ServerlessDb
from the Webcom back end.
Returns:
The returned promised is resolved as soon as the back end acknowledges the cancelation.
- Type
- Promise
clear(atopt) → {Promise}
Asynchronously clears data at this ServerlessDb.ServerlessDbNode
.
This method is equivalent to the ServerlessDb.ServerlessDbNode#set
one passing null
as value.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
at |
ServerlessDb.NOW | ServerlessDb.NEXT_DISCONNECTION | ServerlessDb.ON_DISCONNECTION |
<optional> |
NOW | Write policy to apply for clearing this data node. |
Returns:
- Type
- Promise
get(constraintopt) → {Promise.<ServerlessDb.DataSnapshot>}
Gets the data at this ServerlessDb.ServerlessDbNode
.
This method works asynchronously and can accommodate a loss of network connectivity. If the network is up, the
returned Promise is resolved asynchronously with the value returned by the Webcom back end. If the network
is down, the returned Promise is resolved immediately with the value currently stored in the local cache (or
null
when the cache is empty at this path).
In order to know if the returned value comes from the local cache or from the Webcom back end, check
the ServerlessDb.DataSnapshot#acked
accessor.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
constraint |
ServerlessDb.Constraint |
<optional> |
None | If specified, filters the sub-nodes of this data node. |
Returns:
- Type
- Promise.<ServerlessDb.DataSnapshot>
getCache(constraintopt) → {ServerlessDb.DataSnapshot}
Synchronously returns the value stored in the local cache at the path of this ServerlessDb.ServerlessDbNode
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
constraint |
ServerlessDb.Constraint |
<optional> |
None | If specified, filters the sub-nodes of this data node. |
Returns:
increment(step, startValueopt) → {Promise.<number>}
Atomically increments the value at this ServerlessDb.ServerlessDbNode
.
"Atomically" means that this operation is robust to concurrent increment operations by many clients. It is
guaranteed that if n clients perform an increment at the same time, then the value of the data node ends in
being incremented by n×step
, that is, none of the concurrent operations can overwrite one another.
If the data node has no value, then the increment acts as if it equals the given startValue
.
If the data node has a non-numeric value, then the increment fails.
If you need to perform a more complex operation in an atomic way, use the
ServerlessDb.ServerlessDbNode#runTransaction
method.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
step |
number | The step to add to the current data node value. |
||
startValue |
number |
<optional> |
0 | The default starting value of the data node if it has no value when the increment is performed. |
Returns:
The resulting value of the increment operation.
Note that the returned value may not be synchronized with the actual value of the data node, especially if
other clients perform write operations at the same time. Use rather
subscriptions
to watch the actual value of a data node.
- Type
- Promise.<number>
merge(value, atopt) → {Promise}
Asynchronously merges some data with the data at this ServerlessDb.ServerlessDbNode
.
The requested merge operation is done asynchronously in the same way as the ServerlessDb.ServerlessDbNode#set
method, depending on the chosen policy.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
Object | The value to merge with the current data node. It must be serializable to a regular JSON object. Its 1st-level keys are merged with the ones existing at the current data node. Keys from the value to merge overwrite keys with the same name in the current data. Keys from the current data that don't occur in the value to merge are kept as is. |
||
at |
ServerlessDb.NOW | ServerlessDb.NEXT_DISCONNECTION | ServerlessDb.ON_DISCONNECTION |
<optional> |
NOW | Write policy to apply for merging the value. |
Returns:
- Type
- Promise
push(value) → {Promise.<string>}
Creates a child node of this ServerlessDb.ServerlessDbNode
with a unique key and asynchronously writes a given
value at it.
This method is exactly equivalent to the following chaining of methods:
this.relativeNode(this.generateUniqueKey()).set(value);
Parameters:
Name | Type | Description |
---|---|---|
value |
any | The value to write at the created child node. |
Returns:
The returned Promise is resolved with the key of the created child node.
- Type
- Promise.<string>
relativeNode(relativePath) → {ServerlessDb.ServerlessDbNode}
Returns the data node specified by a path relatively to this ServerlessDb.ServerlessDbNode
.
Parameters:
Name | Type | Description |
---|---|---|
relativePath |
string | The path of the targeted node relatively to this instance, expressed with a
slash-separated string.
|
Returns:
runTransaction(transactionUpdate, onCompleteopt, optionsopt)
Writes data atomically within a transaction at this ServerlessDb.ServerlessDbNode
. This
means the data will be actually written only if the data node is not modified by another client during the
transaction. Otherwise, the transaction is retried (up to 25 times) until it can be completed safely without
conflict.
If the transactionUpdate
function consists in incrementing (or decrementing) the value of the data node, use
rather the ServerlessDb.ServerlessDbNode#increment
method, which is more efficient in this case.
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
transactionUpdate |
function | A 1-argument function that receives the current value of the data node
and is expected to return either an undefined value to abort the transaction, or the new value to overwrite at
the data node. |
|||||||||||||||||
onComplete |
function |
<optional> |
A 3-argument function that is called after the transaction execution whatever its outcome (completed or aborted):
|
||||||||||||||||
options |
Object |
<optional> |
{} |
Properties
|
set(valuenullable, atopt) → {Promise}
Asynchronously writes some data at this ServerlessDb.ServerlessDbNode
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
Object |
<nullable> |
The value to set at the current data node. It must be serializable to a regular JSON
value (e.g. |
|
at |
ServerlessDb.NOW | ServerlessDb.NEXT_DISCONNECTION | ServerlessDb.ON_DISCONNECTION |
<optional> |
NOW | Write policy to apply for setting the value:
|
Returns:
- Type
- Promise
subscribe(event, channel, constraintopt) → {Promise.<ServerlessDb.Subscription>}
Subscribes to a data event to watch on the current ServerlessDb.ServerlessDbNode
through a given
notification channel (ServerlessDb.Callback
or ServerlessDb.Webhook
).
The resulting subscription may be further unsubscribed either by calling the
ServerlessDb.Subscription#cancel
method on the ServerlessDb.Subscription
instance
resolved by the returned Promise
, or by calling the ServerlessDb.ServerlessDbNode#unsubscribe
method (which
doesn't need further a reference to the ServerlessDb.Subscription
instance).
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
event |
ServerlessDb.EventDescriptor | The data event to watch. |
||
channel |
ServerlessDb.Callback | ServerlessDb.Webhook | The channel to use for notifying when subscribed events
are raised.
|
||
constraint |
ServerlessDb.Constraint |
<optional> |
None | For |
Returns:
- Type
- Promise.<ServerlessDb.Subscription>
unsubscribe(channel, notifyCancelationopt) → {Promise}
Unsubscribes a given notification channel (ServerlessDb.Callback
or ServerlessDb.Webhook
) from all
data event previously subscribed to using the ServerlessDb.ServerlessDbNode#subscribe
method on the current
ServerlessDb.ServerlessDbNode
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
channel |
ServerlessDb.Callback | ServerlessDb.Webhook | The channel that unsubscribes events.
|
||
notifyCancelation |
boolean |
<optional> |
false | For |
Returns:
This method will asynchronously resolve the returned Promise when performed.
- Type
- Promise