Skip to main content

automapper/sequelize

Overview

@automapper/sequelize is an official strategy that works with Sequelize. @automapper/sequelize is an extension of @automapper/classes

Installation

npm i @automapper/core @automapper/classes @automapper/sequelize
yarn add @automapper/core @automapper/classes @automapper/sequelize

Usage

Using @automapper/sequelize isn't different from using @automapper/classes. The difference is @automapper/sequelize has a custom preMap that handles how to serialize the sourceObject because of how Sequelize returns the object upon a Retrieve operation and a custom destinationConstructor.

preMap

Use Sequelize#Model.get() if it's available to serialize the sourceObject

destinationConstructor

Use Sequelize#Model.build() if it's available to construct the destinationObject.

We can customize this preMap via MappingStrategyInitializerOptions

const mapper = createMapper({
strategyInitializer: sequelize({
preMap: customPreMap,
destinationConstructor: customDestinationConstructor,
}),
});

Metadata

See @automapper/classes