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
Answers
In theory, with an X DevAPI expression, you should be able to use a simplified flavour of that SQL statement:
So, you can use the API like the following:
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