2

Consider below code:

const items = await Item.query().where( "type", "like", raw("'??'", [`%${term}%`]) ); 

I'm not getting any errors with the code above, but the database returns an empty result set. The created SQL query is below:

select "items".* from "items" where type LIKE '%"mobiles"%' 

Please look at the like mobiles in the above SQL '%"mobiles"%' "" are treated as part of the value and returns an empty result set.

How can avoid "" in the query above?

Edit: Please note that I'm using ObjectionJS as well which uses Knex.

1 Answer 1

2

?? are supposed to be used for a column name.

I've 2 suggestions for you,

  1. use the query without raw at all,
const items = await Item.query().where('type', 'like', `%${term}%`); 
  1. use single ?,
const items = await Item.query().where('type', 'like', raw("'?'", [`%${term}%`])); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.