catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

How to use mysql json function in where clause? #973

Open ThisIsntMyId opened 3 years ago

ThisIsntMyId commented 3 years ago

So I have query which required us to use Mysql json function such JSON_OVERLAP()

I want to use it alongside other array keys in where clause in select function. Is it possible?

Using Medoo::raw() and building query is not possible for us due to the architecture that we chose atm.

At the end we want to build query such as

select * from table_name where and JSON_OVERLAPS('', )

maioradv commented 3 years ago

i need this too. Now we can make a where in two way $db->select('table',[], Medoo::raw('WHERE ALL MY CONDITIONS')); or this way: $db->select('table',[], [ 'myfield' => 1 ]);

it would be very useful to do something hybrid like that $db->select('table',[], [ 'myfield' => 1, Medoo::raw('myfunction(MYFIELD2) = true') ]);

in the (1.7.10) it will be translated with a '0' = myfunction(MYFIELD2) = true (because he wants a column name there) it could be fixed in dataImplode method of medoo extending that class but that's not maintainable.

ThisIsntMyId commented 3 years ago

one workaround for this which works is to use the conditions like this

php

$data = $database->select("products",*, [
    "price[>]" => 1000,
    "id" => Medoo::raw('<id> AND JSON_OVERLAPS(<categories>, "[100,200,300]")')
]);