/kr-persistence-inmemory

koa-rester module for adding in-memoy persistence

Primary LanguageJavaScriptMIT LicenseMIT

kr-persistence-inmemory

ONLY FOR TESTING PURPOSES AND AS AN EXAMPLE!!

koa-rester module for adding in-memoy persistence.

Persistence

Kind: global class

new Persistence(model)

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.

persistence.list(id) ⇒ Promise

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

persistence.create(data) ⇒ Promise

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

persistence.update(id, data) ⇒ Promise

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

persistence.replace(id, data) ⇒ Promise

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

persistence.delete(id) ⇒ Promise

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

persistence.validate(data) ⇒ Error

Validates the data before creating the object

Kind: instance method of Persistence
Returns: Error - An error or null.

Param Type
data Object