Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MongooseAdapter

MongooseAdapter is the communication interface between Pwoli and the Mongoose ORM.

An ORM Adapter defines how Pwoli should interact between that ORM(here Mongoose) for which this ORMAdapter is implemented.

see

Using a different ORM

author

Mahesh S Warrier https://github.com/codespede

Hierarchy

Implements

Index

Constructors

Properties

initialization: Promise<void>

A Promise which resolves when this Component has been successfully initialized.

modelClass: any

The base Model class of the ORM.

validatorMap: {} = ...

This is the object which is used to map the validators in the ORM with the client side validators in Pwoli. Keys of this object are the validator strings for the ORM and the values are the corresponding validators in Pwoli. This is used by assets/js/activeForm.js

Type declaration

  • [key: string]: string

Methods

  • activeAttributes(model: Model): string[]
  • allAttributes(model: Model): string[]
  • Returns all the attributes including the ones in embedded schemas.

    Parameters

    • model: Model

      The model from which the attributes list has to be extracted.

    Returns string[]

    The attributes list as an array.

  • applyPagination(query: {}, pagination: any): {}
  • applySort(query: {}, sort: Sort): {}
  • attributes(): string[]
  • count<T>(query: {}): Promise<number>
  • Returns the count of records based on the query provided.

    Type parameters

    • T: {}

    Parameters

    • query: {}

      The DB query,

      • [key: string]: any

    Returns Promise<number>

    A Promise which resolves to the number of records found.

  • extendableModelClass(): any
  • findAll(query: {}): Promise<Model[]>
  • getActiveValidators(model: Model, attribute: string): {}[]
  • getClientValidationParams(criteria: boolean | {}): {}
  • init(): Promise<void>
  • Initializes the object. This method is invoked at the end of the constructor after the object is initialized with the given configuration.

    Returns Promise<void>

  • isAttributeActive(model: Model, attribute: string): boolean
  • Checks whether the given attribute is an active attribute in the given Model. Active attributes are attributes for which at-least a single validation rule is applied.

    Parameters

    • model: Model

      The Model in which the check is to be performed.

    • attribute: string

      The attribute to be checked.

    Returns boolean

  • isAttributeRequired(model: Model, attribute: string): boolean
  • primaryKey(): string
  • Sets attributes to the Model provided

    Parameters

    • model: Model

      The Model to which attributes are to be set.

    • values: {}

      An object containing the attributes and values to be set. Eg:- { name: 'Mahesh', gender: 'Male' }

      • [key: string]: any

    Returns Model

    The Model itself after the attributes are set.

  • This method validates the given Model with the validation rules set inside it. The results of the validation will be stored in [Model._errors]. If this is an empty array, it can be considered that the validation has passed.

    Parameters

    • model: Model

      The Model in which validation is to be performed.

    Returns Promise<Model>

Generated using TypeDoc