Skip to content

Latest commit

 

History

History
46 lines (34 loc) · 1.18 KB

README.md

File metadata and controls

46 lines (34 loc) · 1.18 KB

sequelize-repository-pattern

MIT Licensed

Package providing the use of the Repository Pattern with sequelize databases.

It supports Pino Logger to get logs.

Installation

npm install sequelize-repository-pattern

Usage

const AbstractRepository = require('sequelize-repository-pattern')
const { MyModel } = require('MyModelFile')
const { logger } = require('MyPinoLogger')

class MyRepository extends AbstractRepository {
  /**
   * Override parent constructor
   */
  constructor () {
    super(Client, logger) // Or, without logger: super(Client)
  }

  /**
   * Create or Update With Conditions
   * @param {BigInteger} conditionalId
   * @param {Object} myObject
   * @returns {Promise<Object>}
   */
  async createOrUpdateByConditionalId (conditionalId, myObject) {
    return await this.createOrUpdate({ conditionalId, name: myObject.name, isActive: true }, { where: { conditionalId } })
  }
}

module.exports = MyRepository

The currently supported methods are:

findOne / findAll / create / update / createOrUpdate / findOrCreate