sequelize-data-sync

1.0.7-b • Public • Published

sequelize-data-sync

  • transfer sequelize db data from one model to another

use

SequelizeDataSync.syncData(
    sourceModel,
    targetModel,
    {
        pivotKey: 'myPropertyName',
        /*
            default: 'id'
            (optional) Default pivot key
        */
 
        sourcePivotKey: 'myPropertyName',
        targetPivotKey: 'myPropertyName',
        /*
            (optional) Override pivotKey for a specific model
        */
        
        include: {
            'singularRelationName': {
                pivotKey: 'otherProperty',
                sourcePivotKey: 'otherProperty',
                targetPivotKey: 'otherProperty'
            },
            'singularRelationName': 'otherProperty',
            'singularRelationName': true,
            ....
        },
        /*
            default: {}
            (optional)
            Only goes one level deep.
            Will establish association with BelongsTo / BelongsToMany relationsßß
            will create new records (if needed) for hasOne / hasMany relations
            
        */
 
        compareOnly: false,
        /*
            default: false
            (optional)
            Only fire callbacks, don't migrate data
        */
 
        /****
        ***** Callbacks
        ****/
 
        // All callbacks are optional
 
        onNewRecord: function(record) {},
 
        onUpdateRecord: function(record, key, newValue, oldValue, isNewRecord) {},
 
        onDeleteRecord: function(record) {},
 
        onNew< singular relation name >: function(relationRecord, record, singularRelationName) {},
        onNewRelated: function(relationRecord, record, singularRelationName) {},
 
        onUpdate< singular relation name >: function(relationRecord, key, oldValue, newValue, record, isNewRecord, singularRelationName) {},
        onUpdateRelated: function(relationRecord, key, oldValue, newValue, record, isNewRecord, singularRelationName) {},
        /*
            Only gets called for a hasOne or hasMany relation
        */
 
        onDelete< singular relation name >: function(relationRecord, record, singularRelationName) {},
        onDeleteRelated: function(relationRecord, record, singularRelationName) {}
    }
);

Roadmap: Testing will be implemented soon, along with updated, more clear documentation

License

MIT

Package Sidebar

Install

npm i sequelize-data-sync

Weekly Downloads

14

Version

1.0.7-b

License

MIT

Last publish

Collaborators

  • chadthomas