-
async, static run(optionsopt, func)
-
Runs a function in transaction if needed, using specified parameters.
If a non-retryable error is thrown while running the transaction, it will
be re-raised.
Parameters:
| Name |
Type |
Attributes |
Description |
options |
ContextOptions
|
<optional>
|
|
func |
function
|
|
the closure to run. |
Example
// Can be called in 2 ways:
Context.run(async (tx) => {
// Do something
})
// Or
Context.run({ retryCount: 2 }, async (tx) => {
// Do something
})
-
-
Creates a model without accessing DB. Write will make sure the doc does
not exist.
Parameters:
| Name |
Type |
Description |
Cls |
Model
|
A Model class. |
data |
CompositeID
|
Object
|
A superset of CompositeID of the model,
plus any data for Fields on the Model. |
-
-
Sets a model's data. Will overwrite the existing data, if any.
Parameters:
| Name |
Type |
Description |
Cls |
Model
|
A Model class. |
data |
CompositeID
|
Object
|
A superset of CompositeID of the model,
plus any data for Fields on the Model. |
-
-
Deletes model(s) from database.
If a model is read from database, but it did not exist when deleting the
doc, an exception is raised.
Parameters:
| Name |
Type |
Attributes |
Description |
args |
List.<(Key|Model)>
|
<repeatable>
|
Keys and Models |
-
-
Enables model cache
-
-
Fetches model(s) from database.
This method supports 3 different signatures.
get(Cls, keyOrDataValues, params)
get(Key|Data, params)
get([Key|Data], params)
Must use a Key when createIfMissing is not true, and Data otherwise.
When a list of docs is fetched:
Firestore getAll API is called.
Batched fetches are more efficient than calling get with 1 key many
times, since there is less HTTP request overhead.
Parameters:
| Name |
Type |
Attributes |
Description |
Cls |
Class
|
|
a Model class. |
key |
String
|
CompositeID
|
|
Key or keyValues |
params |
GetParams
|
<optional>
|
|
Returns:
- Model(s) associated with provided key
-
-
Return before and after snapshots of all relevant models.
Does not include deleted models.
-
-
Marks a transaction as read-only.
-
async updateWithoutRead(key, data)
-
Updates an doc without reading from DB. Fails if doc is not in the db.
Parameters:
| Name |
Type |
Description |
key |
CompositeID
|
The key to update |
data |
Object
|
Updated fields for the doc |