Node.js - Where clause stopped working after updating Knex
Node.js - Where clause stopped working after updating Knex

I've got an node.js app in development using Editor and DataTables, that I've just gotten back to after a bit of a break. I updated all the dependencies, and after fixing a few minor things, I'm having a big problem when using the Where clause functionality in Editor. Every time its called I get the following error:
Unhandled promise error: [object Promise]TypeError: The operator "undefined" is not permitted
app.js:29
stack: TypeError: The operator "undefined" is not permitted
at MSSQL_Formatter.operator (/Dev/members-app/node_modules/knex/lib/formatter.js:203:13)
This was working fine a few months back. Taking the Where clause out, everything works fine. I've tried forcing in the operator to no avail. I'm developing on Mac with VS Code, database is Azure SQL Database.
Any clues??
This question has an accepted answers - jump to answer
Answers
It sounds like it's forming the query wrong. Please can you add debug to the server-side script so we can see the query that's being executed. This thread explains how to add debug.
Colin
Thanks Colin. I've tried a few variations of this, but I may not be using the debug method correctly. When I have it set (without a where clause to test it), the data returns ok in the Json, but the debug element is empty:
"debug":[]}
Yes, unfortunately the linked thread doesn't actually discuss the NodeJS debugging - it is a little different from the PHP and .NET libraries we provide since the NodeJS libraries use Knex for the database abstraction. You need to add
debug: true
to your Knex database configuration object. The SQL statements will then be dumped onto the node console.Can you show me the Editor NodeJS code you are using please?
Thanks,
Allan
Ah, thanks Allan, that did the trick. This will make a massive difference!
So the issue with the Where clause didn't get as far as submitting any SQL, but the debug flag did generate a few clues. I move the Where into a seperate function call after the Editor initialisation, and now it is working again. Not sure why it's changed, but as long as it works, I'm happy.
Thank you both so much for your input!
interesting. We'll keep an ear out for similar issues - but good to hear you've got it working
.
Allan
Hi. I am also experiencing this issue with Editor 1.19.4 and Knex 0.21.1 using mariadb 10.4.13. When adding a where clause to a leftJoin(), the following error is generated:
My Editor definition in Node.js is as follows:
I have debug turned on in Knex, but it is not getting as far as generating a SQL statement.
Thanks in advance for any help!
Kevin
Hi Kevin,
Interesting - could you try this please:
i.e. as an object rather than two parameters?
Thanks,
Allan
Hi Kevin,
When I had the issue, I had to move the Where clause out of the Editor initialisation. So after the let editor =... statement, I have added:
Hi Allan,
Changing to the object rather than the 2 parameters has fixed it - working ok. Thanks very much!
Thanks also to @grapefruitmoon for the tip.
Kevin