|
55 | 55 | * @method static QueryExpression concat(array $params, ?string $alias = null) Build a 'CONCAT' SQL function call
|
56 | 56 | * @method static QueryExpression floor(string|QueryExpression $expression, ?string $alias = null) Build a 'FLOOR' function call
|
57 | 57 | * @method static QueryExpression greatest(array $params, ?string $alias = null) Build a 'GREATEST' function call
|
58 |
| - * @method static QueryExpression jsonContains(array $params, ?string $alias = null) Build a 'JSON_CONTAINS' function call |
59 | 58 | * @method static QueryExpression jsonExtract(array $params, ?string $alias = null) Build a 'JSON_EXTRACT' function call
|
60 | 59 | * @method static QueryExpression jsonUnquote(string|QueryExpression $expression, ?string $alias = null) Build a 'JSON_UNQUOTE' function call
|
61 | 60 | * @method static QueryExpression jsonRemove(array $params, ?string $alias = null) Build a 'JSON_REMOVE' function call
|
@@ -454,4 +453,24 @@ public static function concat_ws(string|QueryExpression $separator, array $param
|
454 | 453 | $separator = $separator instanceof QueryExpression ? $separator : $DB::quoteName($separator);
|
455 | 454 | return new QueryExpression('CONCAT_WS(' . $separator . ', ' . implode(', ', $params) . ')', $alias);
|
456 | 455 | }
|
| 456 | + |
| 457 | + public static function jsonContains(string|QueryExpression $target, string|QueryExpression $candidate, string $path, ?string $alias = null): QueryExpression |
| 458 | + { |
| 459 | + global $DB; |
| 460 | + |
| 461 | + if (is_string($target)) { |
| 462 | + $target = new QueryExpression($DB::quoteName($target)); |
| 463 | + } |
| 464 | + |
| 465 | + if (is_string($candidate)) { |
| 466 | + $candidate = preg_match('/-MariaDB/', $DB->getVersion()) |
| 467 | + ? new QueryExpression($DB::quoteName($candidate)) |
| 468 | + : QueryFunction::cast($candidate, 'JSON') |
| 469 | + ; |
| 470 | + } |
| 471 | + |
| 472 | + $path = new QueryExpression($DB::quoteValue($path)); |
| 473 | + |
| 474 | + return self::getExpression('JSON_CONTAINS', [$target, $candidate, $path], $alias); |
| 475 | + } |
457 | 476 | }
|
0 commit comments