-
Notifications
You must be signed in to change notification settings - Fork 362
Use cases for intent based CRUD hooks
Raymond Feng edited this page Mar 9, 2015
·
14 revisions
We recently received some feedbacks on the intent-based CRUD hooks.
- https://github.com/strongloop/loopback-datasource-juggler/pull/488
- https://github.com/strongloop/loopback-datasource-juggler/issues/482
There are issues and ideas raised. We would like to fully understand the use cases to decide what's the best way to enhance the hook apis, especially the ctx
structure. Community input is critical to make the exercise successful. Please contribute your use cases below.
There are different types of methods that trigger a hook function:
- prototype methods, such as
updateAttributes
,save
, anddelete
. They work on a given model instance. - static methods, such as
create
,updateAll
, anddeleteAll
. They work on the a given model class.
There are a few categories I can see:
- In a
before
hook, perform additional operations. - In a
before
hook, run some validations and fail fast. - In a
before
hook, change/transform the input to the target DB operation. - In a
after
hook, perform additional operations based on the outcome of the CRUD. - In a
after
hook, change/transform the output from the target DB operation so that the callback/promise will receive a modified result.
Use cases from Raymond:
- Calculate a license key for a subscription record before it's save to the DB. The license key is derived from a