1.1.0-alpha • Published 5 years ago

speck-sequelize-repository v1.1.0-alpha

Weekly downloads
7
License
GPL-3.0-only
Repository
github
Last release
5 years ago

Speck Sequelize Repository - Create repositories handle Sequelize models with Speck.

Build Status

This package let you use Speck with repositories to handle Sequelize models.

Installing

$ npm install speck-sequelize-repository

Examples

Sample Repository

const { Repository } = require('speck-sequelize-repository')

const { MySequelizeModel } = require('./models')
const MyModelMap = require('./modelMaps/MyModelMap')

const MyModelRepository = {
  customQuery ({ someField }) {
    return this.findOneByCriterias({ someField })
  }
}

module.exports = Repository.for(MySequelizeModel, MyModelMap, MyModelRepository)

Sample Mapper

Creates a mapper like in object-mapper:

const { Mapper } = require('speck-sequelize-repository')

const map = {
  toEntity: {
    'someField': 'someField'
  },
  toDatabase: {
    'someField': 'someField'
  }
}

module.exports = new Mapper(Object, map)

Auto Mapper

Creates a Mapper without specifying manually the map fields:

  const { AutoMapper } = require('speck-sequelize-repository')
  const mapper = new AutoMapper(someSpeckEntity)

The map fields will be automatically created from a speck entity. Note: entity relationships will have opinionated naming, example: entity.relationship will expect on database a relationship table with relationshipId field.

You can also override some of the automatically generated fields naming, or exclude entity properties from map on AutoMapper constructor:

  const mapper = new AutoMapper(someSpeckEntity, {
     override: {
       entityField: 'otherFieldName',
       entityRelationshipField: 'otherTableName.otherFieldName'
     },
     exclude: ['someEntityProperty']
  )
1.1.0-alpha

5 years ago

1.0.0

5 years ago

0.2.0

5 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.1

7 years ago