Skip to content

Sequelize store broken with sequelize 5 #26

@armellarcier

Description

@armellarcier

Use of global.sequelize and of $lte operator.

I use this patch (with patch-package)

diff --git a/node_modules/koa2-ratelimit/src/SequelizeStore.js b/node_modules/koa2-ratelimit/src/SequelizeStore.js
index f5bceb4..ac3b23b 100644
--- a/node_modules/koa2-ratelimit/src/SequelizeStore.js
+++ b/node_modules/koa2-ratelimit/src/SequelizeStore.js
@@ -1,4 +1,5 @@
 const Sequelize = require('sequelize');
+const Op = Sequelize.Op;
 
 const Store = require('./Store.js');
 
@@ -116,7 +117,7 @@ class SequelizeStore extends Store {
     }
 
     async _increment(table, where, nb = 1, field) {
-        return table.update({ [field]: global.sequelize.literal(`${field} + ${nb}`) }, { where });
+        return table.update({ [field]: this.sequelize.literal(`${field} + ${nb}`) }, { where });
     }
 
     // remove all if time is passed
@@ -124,7 +125,7 @@ class SequelizeStore extends Store {
         const now = new Date();
         await table.destroy({
             where: {
-                date_end: { $lte: now.getTime() },
+                date_end: { [Op.lte]: now.getTime() },
             },
         });
     }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions