Package providing the use of the Repository Pattern with sequelize databases.
It supports Pino Logger to get logs.
npm install sequelize-repository-pattern
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
findOne / findAll / create / update / createOrUpdate / findOrCreate