Members
batching :ModelBatchMapper
Gets a ModelBatchMapper instance containing utility methods to group multiple doc mutations in a single batch.
Type:
- ModelBatchMapper
- Source:
name :String
Gets the name identifier of the model.
Type:
- String
- Source:
Methods
find(doc, docInfoopt, executionOptionsopt) → {Promise.<Result>}
Executes a SELECT query based on the filter and returns the result as an iterable of documents.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
doc |
Object | An object containing the properties that map to the primary keys to filter. |
|||||||||||||||||
docInfo |
Object |
<optional> |
An object containing the additional document information. Properties
|
||||||||||||||||
executionOptions |
Object | String |
<optional> |
An object containing the options to be used for the requests execution or a string representing the name of the execution profile. Properties
|
- Source:
Returns:
A Promise that resolves to a Result instance.
- Type
- Promise.<Result>
Examples
Get user's videos
const result = await videoMapper.find({ userId });
for (let video of result) {
console.log(video.name);
}
Get user's videos from a certain date
videoMapper.find({ userId, addedDate: q.gte(date)});
Get user's videos in reverse order
videoMapper.find({ userId }, { orderBy: { addedDate: 'desc' }});
findAll(docInfoopt, executionOptionsopt) → {Promise.<Result>}
Executes a SELECT query without a filter and returns the result as an iterable of documents.
This is only recommended to be used for tables with a limited amount of results. Otherwise, breaking up the token ranges on the client side should be used.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
docInfo |
Object |
<optional> |
An object containing the additional document information. Properties
|
||||||||||||||||
executionOptions |
Object | String |
<optional> |
An object containing the options to be used for the requests execution or a string representing the name of the execution profile. Properties
|
- Source:
Returns:
A Promise that resolves to a Result instance.
- Type
- Promise.<Result>
get(doc, docInfoopt, executionOptionsopt) → {Promise.<Object>}
Gets the first document matching the provided filter or null when not found.
Note that all partition and clustering keys must be defined in order to use this method.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
doc |
Object | The object containing the properties that map to the primary keys. |
|||||||||
docInfo |
Object |
<optional> |
An object containing the additional document information. Properties
|
||||||||
executionOptions |
Object | String |
<optional> |
An object containing the options to be used for the requests execution or a string representing the name of the execution profile. Properties
|
- Source:
Returns:
- Type
- Promise.<Object>
Examples
Get a video by id
videoMapper.get({ id })
Get a video by id, selecting specific columns
videoMapper.get({ id }, fields: ['name', 'description'])
insert(doc, docInfoopt, executionOptionsopt) → {Promise.<Result>}
Inserts a document.
When the model is mapped to multiple tables, it will insert a row in each table when all the primary keys are specified.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
doc |
Object | An object containing the properties to insert. |
|||||||||||||||||
docInfo |
Object |
<optional> |
An object containing the additional document information. Properties
|
||||||||||||||||
executionOptions |
Object | String |
<optional> |
An object containing the options to be used for the requests execution or a string representing the name of the execution profile. Properties
|
- Source:
Returns:
A Promise that resolves to a Result instance.
- Type
- Promise.<Result>
Example
Insert a video
videoMapper.insert({ id, name });
mapWithQuery(query, paramsHandler, executionOptionsopt) → {function}
Uses the provided query and param getter function to execute a query and map the results. Gets a function that takes the document, executes the query and returns the mapped results.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
query |
String | The query to execute. |
|||||||||||||||||||||||||
paramsHandler |
function | The function to execute to extract the parameters of a document. |
|||||||||||||||||||||||||
executionOptions |
Object | String |
<optional> |
When provided, the options for all executions generated with this method will use the provided options and it will not consider the executionOptions per call. Properties
|
- Source:
Returns:
Returns a function that takes the document and execution options as parameters and returns a Promise the resolves to a Result instance.
- Type
- function
remove(doc, docInfoopt, executionOptionsopt) → {Promise.<Result>}
Deletes a document.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
doc |
Object | A document containing the primary keys values of the document to delete. |
|||||||||||||||||||||
docInfo |
Object |
<optional> |
An object containing the additional doc information. Properties
|
||||||||||||||||||||
executionOptions |
Object | String |
<optional> |
An object containing the options to be used for the requests execution or a string representing the name of the execution profile. Properties
|
- Source:
Returns:
A Promise that resolves to a Result instance.
- Type
- Promise.<Result>
Example
Delete a video
videoMapper.remove({ id });
update(doc, docInfoopt, executionOptionsopt) → {Promise.<Result>}
Updates a document.
When the model is mapped to multiple tables, it will update a row in each table when all the primary keys are specified.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
doc |
Object | An object containing the properties to update. |
|||||||||||||||||||||
docInfo |
Object |
<optional> |
An object containing the additional document information. Properties
|
||||||||||||||||||||
executionOptions |
Object | String |
<optional> |
An object containing the options to be used for the requests execution or a string representing the name of the execution profile. Properties
|
- Source:
Returns:
A Promise that resolves to a Result instance.
- Type
- Promise.<Result>
Example
Update the name of a video
videoMapper.update({ id, name });