koa-rester module for adding Mongo persistence using mongoose.
Kind: global class
- Persistence
- new Persistence(model)
- .list(id) ⇒
Promise
- .create(data) ⇒
Promise
- .update(id, data) ⇒
Promise
- .replace(id, data) ⇒
Promise
- .delete(id) ⇒
Promise
Create a KoaResterPersistence
Param | Type | Description |
---|---|---|
model | Object |
The mongoose model |
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 | String |
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 |