feathersjs-ecosystem / feathers-sequelize

A Feathers service adapter for the Sequelize ORM. Supporting MySQL, MariaDB, Postgres, SQLite, and SQL Server
MIT License
208 stars 75 forks source link

How to use Sequelize increment method with this adapter #303

Closed apmcodes closed 5 years ago

apmcodes commented 5 years ago

Trying to switch to sequelize from mongoose. Unable to replace mongoose $inc with sequelize increment method in a service patch.

            const statsData = { $inc: statUpdateFields };
            return app.service('lists').patch(listId, statsData)

Can alteritems be used to atomically increment a mysql field? If so can you guide.

https://github.com/feathers-plus/feathers-hooks-common/issues/226 http://docs.sequelizejs.com/class/lib/model.js~Model.html#static-method-increment

apmcodes commented 5 years ago

Solved directly using Sequelize model inside the hook, kind of hacky but works.

            const listModel = context.app.service('lists').Model;
            return listModel.increment(statUpdateFields, incOptions)

Events doesn't work with this way...