Why Sequelize Raw Queries don't return records from MySQL when I search by date?

92
January 20, 2022, at 01:30 AM

I have a MySQL database and I try to search in a tale using created_at and updated_at fields which are timestamp fields using this query

SELECT
    user_types.id,
    user_types.name,
    user_types.parent_id,
    user_types.entity_id,
    user_types.deleted_at,
    user_types.created_at,
    user_types.updated_at
  FROM user_types
  WHERE user_types.entity_id='ea438831-74aa-4d1a-80e6-eb31df7e2777' AND user_types.deleted_at IS NULL
  AND (user_types.created_at >= '2022-01-16 22:22:53' OR user_types.updated_at >= '2022-01-16 22:22:53')

But I get 0 records though when I run the same query in phpmyadmin I get the record I'm looking for so why doesn't Sequelize search correctly by date?

connection:

const sequelize = new Sequelize(
process.env.MYSQL_DATABASE,
process.env.MYSQL_USER,
process.env.MYSQL_PASSWORD,
{
  host: process.env.MYSQL_HOST,
  dialect: 'mysql',
  port: process.env.MYSQL_PORT,
  dialectOptions: {
    multipleStatements: true,
    dateStrings: true,
    typeCast(field, next) {
      if (field.type === 'DATETIME') {
        return field.string();
      }
      return next();
    },
  },
  timezone: '+00:00',
  logging: false,
  pool: {
   min: 1,
   max: 500,
   idle: 10000,
   acquire: 60000,
  },
 },
);

I tried AND (DATE(user_types.created_at) >= '2022-01-17 22:6:5' OR DATE(user_types.updated_at) >= '2022-01-17 22:6:5') but it didn't fetch the record I can fetch from phpmyadmin

Answer 1

Where is your sequelize query ?

Rent Charter Buses Company
READ ALSO
Web Push Same Subscriber Different Endpoint Issue

Web Push Same Subscriber Different Endpoint Issue

I am trying to implement the web-push service in one of my projectsSo, I actually need to know the actual subscriber numbers in my app

112
Why is the html view port meta tag breaking my CSS when I want to make my page responsive?

Why is the html view port meta tag breaking my CSS when I want to make my page responsive?

I am working on a small website for uni and have started out by designing the mobile site firstIt looked exactly how I wanted it to look on a 320px mobile device

94
SOLVED - addClass only once onClick ReactJS

SOLVED - addClass only once onClick ReactJS

Hi I'm new to ReactJS so I'm importing some work of mine to my project and turning it into componentsI have a span acting as a button with keyframe animations, but when i load the page it gets animated

126
Can't understand code of getRefreshKey in Android paging3 codelab

Can't understand code of getRefreshKey in Android paging3 codelab

This is the code of getRefreshKey function of the paging3 codelab

158