Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Op.between fails to convert arguments to Date strings #10563

Closed
broofa opened this issue Mar 15, 2019 · 1 comment
Closed

Op.between fails to convert arguments to Date strings #10563

broofa opened this issue Mar 15, 2019 · 1 comment

Comments

@broofa
Copy link
Contributor

broofa commented Mar 15, 2019

What are you doing?

Querying a DataType.DATE column using Op.between.

const Op = sequelize.Sequelize.Op;
const Event = sequelize.define('Event', {
  rowid: {type: DataTypes.INTEGER, primaryKey: true},
  time: {type: DataTypes.DATE, allowNull: false},
}, {
  tableName: 'events',
  name: {singular: 'event', plural: 'events'},
  timestamps: false,
});

// LTE + GTE query
Event.findAll({where: {time: {[Op.and]: [{[Op.gte]: 0}, {[Op.lte]: 10}]}}});

// BETWEEN query
Event.findAll({where: {time: {[Op.between]: [0, 10]}}});

What do you expect to happen?

As BETWEEN is simply shorthand for val >= min AND val <= max, I would expect conversion to column types to be handled similarly. That is, the two queries above should generate functionally equivalent SQL like this:

SELECT `rowid`, `time` FROM `events` AS `Foo` WHERE (`Foo`.`time` >= '1970-01-01 00:00:00.000 +00:00' AND `Foo`.`time` <= '1970-01-01 00:00:00.010 +00:00');
SELECT `rowid`, `time` FROM `events` AS `Foo` WHERE `Foo`.`time` BETWEEN '1970-01-01 00:00:00.000 +00:00' AND '1970-01-01 00:00:00.010 +00:00';

What is actually happening?

The BETWEEN query fails to convert the min/max values to Date strings, instead injecting them as raw values:

SELECT `rowid`, `time` FROM `events` AS `Foo` WHERE (`Foo`.`time` >= '1970-01-01 00:00:00.000 +00:00' AND `Foo`.`time` <= '1970-01-01 00:00:00.010 +00:00');
SELECT `rowid`, `time` FROM `events` AS `Foo` WHERE `Foo`.`time` BETWEEN 0 AND 10;

Dialect: sqlite
Dialect version: XXX
Database version: 3.19.3 2017-06-27 16:48:08 2b0954060fe10d6de6d479287dd88890f1bef6cc1beca11bc6cdb79f72e2377b
Sequelize version: sequelize@5.1.0
Tested with latest release: Yes (5.1.0)

@sushantdhiman
Copy link
Contributor

🎉 This issue has been resolved in version 5.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants