Tuesday, 23 May 2017

KnexJS Raw Method doesn't work in one case

Working with KnexJS on a project and have been using the .raw() method throughout the project with out a single issue.

I now have one case where the .raw is just not being built into the SQL, and so I end up with the syntax error at end of input error. If I dump the SQL string, I can see why as it's failing

'update "mytable" set "a" = ? returning '

I can see why it's having an issue, the problem I'm having is that the returning is a Raw value as such, and so I just can't figure out why it's not being compiled with the SQL.

knexQuery.update(data).into('mytable').returning( knexQuery.raw('mytable::json') );`

If I use a string, in place of the raw in the returning() method, it will compile the string into it.

If I console out the knexQuery.raw('mytable::json') part, it shows as a Raw object, with the right object data...

Raw {
 client: 
  Client_PG {
    ... },
 sql: 'mytable::json',
 bindings: undefined,
 _wrappedBefore: undefined,
 _wrappedAfter: undefined,
 _debug: undefined } }

I know that the SQL works, as I've filled in the missing part and it works, but the SQL is not the issue, I just can't figure out why the raw() method is not being compiled with the SQL string.

I also have another piece of code (and INSERT one) somewhere else in my code that is using the same returning( knexQuery.raw(....) ) and that works perfectly fine.

I'm starting to think this is a bug in the code, but after spending an hour going through the KnexJS library code, I can't see any reason why it would not work.

So why does this code not build the raw into the query, while my other one has no problem and works?

I'm getting to the point where I just want to use something else to get around the problem, but it's just not possible without using this method.



via Guy Park

No comments:

Post a Comment