ONLY FOR TESTING PURPOSES AND AS AN EXAMPLE!!
koa-rester module for adding in-memoy persistence.
Kind: global class
- Persistence
- new Persistence(model)
- .list(id) ⇒
Promise
- .create(data) ⇒
Promise
- .update(id, data) ⇒
Promise
- .replace(id, data) ⇒
Promise
- .delete(id) ⇒
Promise
- .validate(data) ⇒
Error
Create a KoaResterPersistence
Param | Type | Description |
---|---|---|
model | Object |
The ORM native model to be wrapped, in this case as there is no ORM it will be an empty object. |
If id is provided, it tries to get the element with the given id. It will throw an error if no element is found. If no id is provided lists all the stored items.
Kind: instance method of Persistence
Returns: Promise
- Resolved with the object or the array of objects or
rejected with an error.
Async:
Param | Type |
---|---|
id | Number |
Creates a new object with the given data.
Kind: instance method of Persistence
Returns: Promise
- Resolved with the new object or rejected with an error.
Param | Type |
---|---|
data | Object |
Updates an existing object with the given data.
Kind: instance method of Persistence
Returns: Promise
- Resolved with the old object or rejected with an error.
Param | Type | Description |
---|---|---|
id | Number |
The object id |
data | Object |
The fields to be updated |
Replaces an existing object by a new one created with the given data.
Kind: instance method of Persistence
Returns: Promise
- Resolved with the old object or rejected with an error.
Param | Type | Description |
---|---|---|
id | Number |
The id of the object to be replaced |
data | Object |
The new object data |
Deletes an existing object.
Kind: instance method of Persistence
Returns: Promise
- Resolved with the removed object or rejected with an error.
Param | Type | Description |
---|---|---|
id | Number |
The id of the object to be deleted |
Validates the data before creating the object
Kind: instance method of Persistence
Returns: Error
- An error or null.
Param | Type |
---|---|
data | Object |