You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The json type is an important feature starting from MySQL 5.7 and is becoming more and more popular, but it is not well experienced in the use of Medoo. So I have some preliminary ideas:
Add [$] tag to implement json path, like column[$] or column[$.a]
$database->select("t", "c[$.name]"); // select c->"$.name" from t;
$database->select("t", "c", ["c[$.name]" => "ben"]); // select c from t where c->"$.name" = "ben";
$database->select("t", "c", ["c[$.age][>]" => 18]); // select c from t where c->"$.age" > 18;
Add ->json function to implement modify json values
$database->json->insert("t", ["c[$.sex]" => "female"]); // update t set c = JSON_INSERT(c, "$.sex", "female");
$database->json->set("t", ["c[$.sex]" => "male"]); // update t set c = JSON_SET(c, "$.sex", "male");
$database->json->replace("t", ["c[$.sex]" => "male"]); // update t set c = JSON_REPLACE(c, "$.sex", "male");
$database->json->remove("t", ["c[$.sex]" => "male"]); // update t set c = JSON_REMOVE(c, "$.sex", "male");
Medoo::raw support JSON_CONTAINS, JSON_LENGTH, JSON_OVERLAPS and so on
$database->select("t", "c", [Medoo::raw("JSON_CONTAINS(c, 'nick', '$.child')") => 1]); // select c from t where JSON_CONTAINS(c, 'nick', '$.child') = 1;
$database->select("t", "c", [Medoo::raw("JSON_LENGTH(c, '$.child')") => 0]); // select c from t where JSON_LENGTH(c, '$.child') = 0;
but Medoo::raw return object that cannot be the key of the array, maybe change the return to string with json_encode
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The json type is an important feature starting from MySQL 5.7 and is becoming more and more popular, but it is not well experienced in the use of Medoo. So I have some preliminary ideas:
Add
[$]
tag to implement json path, likecolumn[$]
orcolumn[$.a]
$database->select("t", "c[$.name]");
// select c->"$.name" from t;$database->select("t", "c", ["c[$.name]" => "ben"]);
// select c from t where c->"$.name" = "ben";$database->select("t", "c", ["c[$.age][>]" => 18]);
// select c from t where c->"$.age" > 18;Add
->json
function to implement modify json values$database->json->insert("t", ["c[$.sex]" => "female"]);
// update t set c = JSON_INSERT(c, "$.sex", "female");$database->json->set("t", ["c[$.sex]" => "male"]);
// update t set c = JSON_SET(c, "$.sex", "male");$database->json->replace("t", ["c[$.sex]" => "male"]);
// update t set c = JSON_REPLACE(c, "$.sex", "male");$database->json->remove("t", ["c[$.sex]" => "male"]);
// update t set c = JSON_REMOVE(c, "$.sex", "male");Medoo::raw support
JSON_CONTAINS, JSON_LENGTH, JSON_OVERLAPS
and so on$database->select("t", "c", [Medoo::raw("JSON_CONTAINS(c, 'nick', '$.child')") => 1]);
// select c from t where JSON_CONTAINS(c, 'nick', '$.child') = 1;$database->select("t", "c", [Medoo::raw("JSON_LENGTH(c, '$.child')") => 0]);
// select c from t where JSON_LENGTH(c, '$.child') = 0;but Medoo::raw return object that cannot be the key of the array, maybe change the return to string with json_encode
Beta Was this translation helpful? Give feedback.
All reactions