Uhh .. There is data in the database and one of the columns contains json of the form

{ "Иван": "100 лет", "Сергей Николаевич": "25 лет", "Сергей": "7 лет", "Элеонора Алефтиновна (массаж)": "+7 (654) 985-95-95" } 

An array comes with a list of keys for which you need to make a selection, for example

 const data = ["Сергей", "Элеонора Алефтиновна (массаж)"] 

knex I make a request

 db.select('*').from('user').whereRaw('?? \\?& ?', ['user_name', data]) 

data - this is exactly this very array with the keys that need to be sampled.

And everything works well. With this query, the result will be:

 { "Сергей": "7 лет","Элеонора Алефтиновна (массаж)": "+7 985 985 95 95" } 

And I would also like to see "Sergey Nikolayevich": "25 years" recorded this result because name Sergei, in the database, appears twice.

The question is how to organize such / e query / s to the database? Those. if the key contains two or more words, and there is only one element / s in the array for which the sample is taken.

Those. somehow check whether the key contains the given word from the array.

    1 answer 1

    You can swap the value and key and do not strict search!

    • This is the answer to the question! - Andrey Zimin
    • Live and learn ... - Air