PyropeActions
Constructor Summary
Public Constructor | ||
public |
constructor(opts: object) PyropeActions |
Member Summary
Public Members | ||
public |
|
|
public |
tableName: * |
|
public |
tablePrefix: * |
|
public |
tableSuffix: * |
Method Summary
Public Methods | ||
public |
Returns an array with the mappings for every record in the table. |
|
public |
Creates associations between entities |
|
public |
Returns the table's item count |
|
public |
Creates a new record in the specified table. |
|
public |
decreaseCounter(opts: *): * |
|
public |
Deletes an item |
|
public |
dissociate(opts: Object): Promise<Boolean> Dissociates two items if an association is found |
|
public |
findByIndex(opts: object): Promise<array | boolean> Queries a table and looks for items matching the specified index. |
|
public |
first(opts: {}): * |
|
public |
getAssociations(opts: *): Promise Returns the associations of the specified item with respect to another item |
|
public |
increaseCounter(opts: *): * |
|
public |
last(opts: {}): * |
|
public |
take(opts: {}): * |
|
public |
Updates an item |
|
public |
updateCounter(opts: *): * |
Public Constructors
Public Members
public fullTableName: * source
public tableName: * source
public tablePrefix: * source
public tableSuffix: * source
Public Methods
public all(): Promise<array> source
Returns an array with the mappings for every record in the table.
Results are returned sorted ascending. You can specify a limit and a cursor to do batch fetching.
opts = {
ascending: Boolean, // Should the results be returned in a ascending manner?
limit: Integer, // The amount of items to fetch
cursor: String // A base64 encoded map of the key containing {uuid: String, createdAt: Number, _table: String}
}
Return:
Promise<array> | An array with the QUERY result, has the structure {Items: [], Count: 0, Cursor: ''} @TODO: Select specific fields to return. |
public associate(opts: Object): Boolean | Promise source
Creates associations between entities
Handles 1:1, 1:N and N:N associations. (!) Does not check for the existence of the items.
opts = {
tableName: String,
items: [
{
index: {[indexName]: '123'}, // Can specify multiple values to associate
[hasMany: Boolean = false] // Used to specify 1:N and 1:N associations
}
]
}
Params:
Name | Type | Attribute | Description |
opts | Object | The options object. |
public create(opts: object): object source
Creates a new record in the specified table.
It will create the record without any conditions. The following fields are auto-generated: uuid, createdAt, updatedAt
opts = {
tableName: 'users',
fields: {
username: 'someguy55',
password: 'myPassword123'
}
}
return = {
uuid: '3f3e1091-8e43-41ca-a19a-881241370c31' // String = 'S'
username: 'someguy55', // String = 'S'
password: 'myPassword123' // String = 'S'
createdAt: 1470345881706, // Number = 'N'
updatedAt: 1470345881755 // Number = 'N'
}
Params:
Name | Type | Attribute | Description |
opts | object | Options mapping. |
Return:
object | The fields of the newly created record, rejection on error @todo: Handle unprocessedItems @todo: Handle failed increaseCounter() @todo: let uuid, createdAt, updatedAt to be cofigurable ? |
public destroy(opts: Object): Object | Boolean source
Deletes an item
Previously checks using findByIndex() if the item exits. If it doesn't, returns false, otherwise returns the deleted item.
opts = {
tableName: String,
index: Object, // Index used to query the item.
}
Params:
Name | Type | Attribute | Description |
opts | Object | Options mapping |
public dissociate(opts: Object): Promise<Boolean> source
Dissociates two items if an association is found
item[0].uuid should be a scalar item[1].uuid can be an array of associations to remove.
opts = {
tableName: String,
items: [
{
index: {indexName: any}, // index values should be a scalar
},
{
index: {indexName: [any]}, // index values can be an array
}
]
}
Params:
Name | Type | Attribute | Description |
opts | Object | The options object |
public findByIndex(opts: object): Promise<array | boolean> source
Queries a table and looks for items matching the specified index.
The index mapping has the following structure:
index = {
username: 'john'
}
In order to find the table's index, the word 'Index' is appended, resulting in this example in 'usernameIndex'
Every index has a 'createdAt' range key. This is calculated and appended automatically before querying.
opts = {
tableName: String,
index: {hash: value, [range: value]},
ascending: Boolean
}
Params:
Name | Type | Attribute | Description |
opts | object | Options mapping. |
Return:
Promise<array | boolean> | Array when there are multiple matches, false when not found |
public first(opts: {}): * source
Params:
Name | Type | Attribute | Description |
opts | {} |
|
Return:
* |
public getAssociations(opts: *): Promise source
Returns the associations of the specified item with respect to another item
opts = {
tableName: String,
items: [
{
index: {key: value}
},
{
index: String
}
]
}
Params:
Name | Type | Attribute | Description |
opts | * |
TODO:
- accept query expressions
public last(opts: {}): * source
Params:
Name | Type | Attribute | Description |
opts | {} |
|
Return:
* |
public take(opts: {}): * source
Params:
Name | Type | Attribute | Description |
opts | {} |
|
Return:
* |
public update(opts: Object): Object | Boolean source
Updates an item
Previously checks using findByIndex() if the item exits. If it doesn't, returns false.
opts = {
tableName: String,
index: Object, // Index used to query the item.
args: Object, // Key-Value mapping of the arguments to change.
beforeHook: (attrName, args) Function // Callback function for every field.
Used to modify the key-value mapping of the fields to
change before the item is updated. Must return object of
shape {fieldName: value}
Attribute names may be also modified.
}
Params:
Name | Type | Attribute | Description |
opts | Object | Options mapping |