1

In MySQL shell I am able to run

select * from meeting where startTime > date_add(now(), interval 2 day);

This same command is not working using MySQL XDev API

var meetingRows = (await sqldb.getTable('meeting').select().where('startTime > DATE_ADD(NOW(), interval 2 DAY)').execute()).fetchAll()

I am getting error

-- PARSING FAILED --------------------------------------------------

> 1 | DATE_ADD(NOW(), interval 2 DAY)
    |                          ^

Expected one of the following: 

'!=', '%', '&&', '&', '*', '+', ',', '-', '/', '<', '<<', '<=', '<>', '=', '==', '>', '>=', '>>', '^', 'and', 'between', 'div', 'in', 'is', 'like', 'not', 'or', 'overlaps', 'regexp', '|', '||'

    at _.tryParse (/usr/src/app/node_modules/parsimmon/src/parsimmon.js:928:15)
    at Object.parse (/usr/src/app/node_modules/@mysql/xdevapi/lib/ExprParser/index.js:46:27)
    at Object.getValue (/usr/src/app/node_modules/@mysql/xdevapi/lib/DevAPI/ProjectedSearchExprStr.js:88:27)
    at /usr/src/app/node_modules/@mysql/xdevapi/lib/DevAPI/Table.js:276:95
    at Array.map (<anonymous>)
    at Object.select (/usr/src/app/node_modules/@mysql/xdevapi/lib/DevAPI/Table.js:276:18)

What is wrong in my code? How can I make this working?

2
  • what's with the backticks around the where argument? Commented Jul 7, 2023 at 18:17
  • backtick is just to create string. I have changed backtick to single quote Commented Jul 7, 2023 at 18:20

1 Answer 1

0

In theory, with an X DevAPI expression, you should be able to use a simplified flavour of that SQL statement:

NOW() + interval 2 DAY
CURDATE() + interval 2 DAY

So, you can use the API like the following:

.where('startTime > NOW() + interval 2 DAY')

In practice, I think it's not really working, so you can still use the regular SQL with session.sql().

I suggest you report a bug at https://bugs.mysql.com/ using the Connector for Node.js category.

Disclaimer: I'm the lead developer of the MySQL X DevAPI connector for Node.js

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.