From 3bb174a10985953dc3a909e67e893bb4bc4102be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Capote=20P=C3=A9rez-Andreu?= Date: Sat, 20 May 2023 15:45:31 +0100 Subject: [PATCH] feat: string concatenation --- src/Function/String/Concat.php | 26 ++++++++++++++++++++++++++ tests/Function/String/ConcatTest.php | 13 +++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/Function/String/Concat.php create mode 100644 tests/Function/String/ConcatTest.php diff --git a/src/Function/String/Concat.php b/src/Function/String/Concat.php new file mode 100644 index 0000000..8280b76 --- /dev/null +++ b/src/Function/String/Concat.php @@ -0,0 +1,26 @@ +getExpressions($grammar); + $expressionsStr = implode(', ', $expressions); + + return match ($this->identify($grammar)) { + 'mysql', 'pgsql', 'sqlsrv' => "concat({$expressionsStr})", + 'sqlite' => implode(' || ', $expressions), + }; + } +} diff --git a/tests/Function/String/ConcatTest.php b/tests/Function/String/ConcatTest.php new file mode 100644 index 0000000..24c051e --- /dev/null +++ b/tests/Function/String/ConcatTest.php @@ -0,0 +1,13 @@ +expect(new Concat(['Hello', ' ', 'World'])) + ->toBeExecutable() + ->toBeMysql('concat(`Hello`, ` `, `World`)') + ->toBePgsql('concat("Hello", " ", "World")') + ->toBeSqlite('"Hello" || " " || "World"') + ->toBeSqlsrv('concat([Hello], [ ], [World])');