Options
All
  • Public
  • Public/Protected
  • All
Menu

objection-before-and-unique 0.5.0

Index

Type aliases

TBefore

TBefore: function

Each of the before hooks to be run. See IOptions.

Should throw an error for failed checks. For consistency, it would be recommended that you use the built-in ValidationError via Model.createValidationError() to throw it. You can optionally also mutate the the instance object before it is persisted.

Type declaration

    • (opts: object): Promise<void> | void
    • Parameters

      • opts: object
        • Model: Model

          Objection Model

        • context: QueryContext

          The query context object.

        • instance: TModel

          The new model instance created on insert/update/patch. Keep in mind that, if the operation is a patch, the instance data might not be complete.

        • Optional old?: TModel

          The old model instance (with the values prior to the update/patch operation). It is undefined when the operation is an insert (as there is no previous instance), and inexistent/not passed when IOptions.old is set to false.

        • operation: TOperation

          The type of operation the hook was executed for.

      Returns Promise<void> | void

TMixin

TMixin: function

See obau().

Type declaration

    • <T>(Model: T & Model): T
    • Type parameters

      • T

      Parameters

      • Model: T & Model

      Returns T

TModel

TModel: Model & object

TOperation

TOperation: "insert" | "update" | "patch"

TOrder

TOrder: "before" | "unique" | "schema"

TUniqueFn

TUniqueFn: function

A function definition of uniqueness.

  • If funtion returns a query, if will be considered unique if there are no resolved instances.
  • If the function resolves with a boolean, it will be considered unique when false, and fail when true.

Type declaration

    • (options: object): boolean | QueryBuilder<any, any, any> | Promise<boolean> | Promise<void | Model | Model[]>
    • Parameters

      • options: object
        • Model: Model

          Objection Model

        • instance: TModel

          New model instance being tested for uniqueness

        • Optional old?: TModel

          Old instance, if the operation is an update/patch and it's available

        • operation: TOperation

          Current operation

      Returns boolean | QueryBuilder<any, any, any> | Promise<boolean> | Promise<void | Model | Model[]>

Functions

obau

  • Default export on module entry point. Returns a function to mixin your Model with. See IOptions.

    Usage:

     import { Model } from 'objection';
     import obau from 'objection-before-and-unique';
    
     class MyModel extends obau({
       // ...options
     })(Model) {
       // ...
     }

    Parameters

    Returns TMixin

Generated using TypeDoc