| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Data\Persistence\Sql\Postgresql; |
| 6: | |
| 7: | use Atk4\Data\Persistence\Sql\Expression as BaseExpression; |
| 8: | use Atk4\Data\Persistence\Sql\Query as BaseQuery; |
| 9: | |
| 10: | class Query extends BaseQuery |
| 11: | { |
| 12: | use ExpressionTrait; |
| 13: | |
| 14: | protected string $identifierEscapeChar = '"'; |
| 15: | protected string $expressionClass = Expression::class; |
| 16: | |
| 17: | protected string $templateUpdate = 'update [table][join] set [set] [where]'; |
| 18: | protected string $templateReplace; |
| 19: | |
| 20: | #[\Override] |
| 21: | protected function _subrenderCondition(array $row): string |
| 22: | { |
| 23: | if (count($row) >= 3) { |
| 24: | [$field, $cond, $value] = $row; |
| 25: | if (in_array(strtolower($cond), ['like', 'not like', 'regexp', 'not regexp'], true)) { |
| 26: | $field = $this->expr('CAST([] AS citext)', [$field]); |
| 27: | $row = [$field, $cond, $value]; |
| 28: | } |
| 29: | } |
| 30: | |
| 31: | return parent::_subrenderCondition($row); |
| 32: | } |
| 33: | |
| 34: | #[\Override] |
| 35: | protected function _renderLimit(): ?string |
| 36: | { |
| 37: | if (!isset($this->args['limit'])) { |
| 38: | return null; |
| 39: | } |
| 40: | |
| 41: | return ' limit ' . (int) $this->args['limit']['cnt'] |
| 42: | . ' offset ' . (int) $this->args['limit']['shift']; |
| 43: | } |
| 44: | |
| 45: | #[\Override] |
| 46: | public function groupConcat($field, string $separator = ','): BaseExpression |
| 47: | { |
| 48: | return $this->expr('string_agg({}, [])', [$field, $separator]); |
| 49: | } |
| 50: | } |
| 51: | |