From 14ba71dca5c48466fb2a041ec0aff3218a84b9af Mon Sep 17 00:00:00 2001 From: Magnus Nordlander Date: Tue, 28 May 2019 14:48:17 +0200 Subject: [PATCH 1/6] Made it possible for the TO_* functions to take more varied arguments --- src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJson.php | 2 +- src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJsonb.php | 2 +- .../Doctrine/ORM/Query/AST/Functions/ToTsquery.php | 2 +- .../Doctrine/ORM/Query/AST/Functions/ToTsvector.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJson.php b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJson.php index f2f00041..981aaa1e 100644 --- a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJson.php +++ b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJson.php @@ -17,6 +17,6 @@ class ToJson extends BaseFunction protected function customiseFunction(): void { $this->setFunctionPrototype('to_json(%s)'); - $this->addNodeMapping('InputParameter'); + $this->addNodeMapping('NewValue'); } } diff --git a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJsonb.php b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJsonb.php index 804a6114..1271cc3d 100644 --- a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJsonb.php +++ b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJsonb.php @@ -17,6 +17,6 @@ class ToJsonb extends BaseFunction protected function customiseFunction(): void { $this->setFunctionPrototype('to_jsonb(%s)'); - $this->addNodeMapping('InputParameter'); + $this->addNodeMapping('NewValue'); } } diff --git a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsquery.php b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsquery.php index f68216d2..9c5fec73 100644 --- a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsquery.php +++ b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsquery.php @@ -17,6 +17,6 @@ class ToTsquery extends BaseFunction protected function customiseFunction(): void { $this->setFunctionPrototype('to_tsquery(%s)'); - $this->addNodeMapping('StringPrimary'); + $this->addNodeMapping('NewValue'); } } diff --git a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvector.php b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvector.php index d504e0cd..de6c0b4c 100644 --- a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvector.php +++ b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvector.php @@ -17,6 +17,6 @@ class ToTsvector extends BaseFunction protected function customiseFunction(): void { $this->setFunctionPrototype('to_tsvector(%s)'); - $this->addNodeMapping('StringExpression'); + $this->addNodeMapping('NewValue'); } } From 748295f8288135bcf0e4dac5a373c74f6901f935 Mon Sep 17 00:00:00 2001 From: Magnus Nordlander Date: Wed, 29 May 2019 14:28:40 +0200 Subject: [PATCH 2/6] Added test cases --- .../Doctrine/ORM/Query/AST/Functions/ToTsqueryTest.php | 8 ++++++++ .../ORM/Query/AST/Functions/ToTsvectorTest.php | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsqueryTest.php b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsqueryTest.php index f8d4b581..15d8eae9 100644 --- a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsqueryTest.php +++ b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsqueryTest.php @@ -20,6 +20,10 @@ protected function getExpectedSqlStatements(): array { return [ 'SELECT to_tsquery(c0_.text) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_tsquery(UPPER(c0_.text)) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_tsquery(1 + 1) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_tsquery(1) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_tsquery(LENGTH(c0_.text)) AS sclr_0 FROM ContainsText c0_', ]; } @@ -27,6 +31,10 @@ protected function getDqlStatements(): array { return [ \sprintf('SELECT TO_TSQUERY(e.text) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_TSQUERY(UPPER(e.text)) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_TSQUERY(1+1) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_TSQUERY(true) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_TSQUERY(LENGTH(e.text)) FROM %s e', ContainsText::class), ]; } } diff --git a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php index 479f98f0..1d81245e 100644 --- a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php +++ b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php @@ -20,13 +20,19 @@ protected function getExpectedSqlStatements(): array { return [ 'SELECT to_tsvector(c0_.text) AS sclr_0 FROM ContainsText c0_', - ]; + 'SELECT to_tsvector(LOWER(c0_.text)) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_tsvector(1 + 1) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_tsvector(1) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_tsvector(LENGTH(c0_.text)) AS sclr_0 FROM ContainsText c0_', ]; } protected function getDqlStatements(): array { return [ \sprintf('SELECT TO_TSVECTOR(e.text) FROM %s e', ContainsText::class), - ]; + \sprintf('SELECT TO_TSVECTOR(LOWER(e.text)) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_TSVECTOR(1+1) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_TSVECTOR(true) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_TSVECTOR(LENGTH(e.text)) FROM %s e', ContainsText::class), ]; } } From b0a592c5c6c5e751ee7844923abafec0a35a0fb4 Mon Sep 17 00:00:00 2001 From: Magnus Nordlander Date: Wed, 29 May 2019 14:30:07 +0200 Subject: [PATCH 3/6] Fixed typo --- .../Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php index 1d81245e..07460027 100644 --- a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php +++ b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php @@ -33,6 +33,7 @@ protected function getDqlStatements(): array \sprintf('SELECT TO_TSVECTOR(LOWER(e.text)) FROM %s e', ContainsText::class), \sprintf('SELECT TO_TSVECTOR(1+1) FROM %s e', ContainsText::class), \sprintf('SELECT TO_TSVECTOR(true) FROM %s e', ContainsText::class), - \sprintf('SELECT TO_TSVECTOR(LENGTH(e.text)) FROM %s e', ContainsText::class), ]; + \sprintf('SELECT TO_TSVECTOR(LENGTH(e.text)) FROM %s e', ContainsText::class), + ]; } } From 3dbb51303f62598738e8ef5f4ccb2fa8b10eaaa3 Mon Sep 17 00:00:00 2001 From: Magnus Nordlander Date: Wed, 29 May 2019 14:31:37 +0200 Subject: [PATCH 4/6] Fixed more typos --- .../Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php index 07460027..fcf09e59 100644 --- a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php +++ b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php @@ -23,7 +23,8 @@ protected function getExpectedSqlStatements(): array 'SELECT to_tsvector(LOWER(c0_.text)) AS sclr_0 FROM ContainsText c0_', 'SELECT to_tsvector(1 + 1) AS sclr_0 FROM ContainsText c0_', 'SELECT to_tsvector(1) AS sclr_0 FROM ContainsText c0_', - 'SELECT to_tsvector(LENGTH(c0_.text)) AS sclr_0 FROM ContainsText c0_', ]; + 'SELECT to_tsvector(LENGTH(c0_.text)) AS sclr_0 FROM ContainsText c0_', + ]; } protected function getDqlStatements(): array From 15bfa7cb4b7730223eaed2e7ea72d3dca1390efc Mon Sep 17 00:00:00 2001 From: Magnus Nordlander Date: Wed, 29 May 2019 16:57:06 +0200 Subject: [PATCH 5/6] Undid changes to TO_TSVECTOR and TO_TSQUERY, added tests for TO_JSON and TO_JSONB. --- .../ORM/Query/AST/Functions/ToTsquery.php | 2 +- .../ORM/Query/AST/Functions/ToTsvector.php | 2 +- .../ORM/Query/AST/Functions/ToJsonTest.php | 40 +++++++++++++++++++ .../ORM/Query/AST/Functions/ToJsonbTest.php | 40 +++++++++++++++++++ .../ORM/Query/AST/Functions/ToTsqueryTest.php | 6 --- .../Query/AST/Functions/ToTsvectorTest.php | 6 --- 6 files changed, 82 insertions(+), 14 deletions(-) create mode 100644 tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJsonTest.php create mode 100644 tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJsonbTest.php diff --git a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsquery.php b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsquery.php index 9c5fec73..f68216d2 100644 --- a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsquery.php +++ b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsquery.php @@ -17,6 +17,6 @@ class ToTsquery extends BaseFunction protected function customiseFunction(): void { $this->setFunctionPrototype('to_tsquery(%s)'); - $this->addNodeMapping('NewValue'); + $this->addNodeMapping('StringPrimary'); } } diff --git a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvector.php b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvector.php index de6c0b4c..e0276f27 100644 --- a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvector.php +++ b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvector.php @@ -17,6 +17,6 @@ class ToTsvector extends BaseFunction protected function customiseFunction(): void { $this->setFunctionPrototype('to_tsvector(%s)'); - $this->addNodeMapping('NewValue'); + $this->addNodeMapping('StringPrimary'); } } diff --git a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJsonTest.php b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJsonTest.php new file mode 100644 index 00000000..8e6e60f3 --- /dev/null +++ b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJsonTest.php @@ -0,0 +1,40 @@ + ToJson::class, + ]; + } + + protected function getExpectedSqlStatements(): array + { + return [ + 'SELECT to_json(c0_.text) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_json(UPPER(c0_.text)) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_json(1 + 1) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_json(1) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_json(LENGTH(c0_.text)) AS sclr_0 FROM ContainsText c0_', + ]; + } + + protected function getDqlStatements(): array + { + return [ + \sprintf('SELECT TO_JSON(e.text) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_JSON(UPPER(e.text)) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_JSON(1+1) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_JSON(true) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_JSON(LENGTH(e.text)) FROM %s e', ContainsText::class), + ]; + } +} diff --git a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJsonbTest.php b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJsonbTest.php new file mode 100644 index 00000000..c223808a --- /dev/null +++ b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToJsonbTest.php @@ -0,0 +1,40 @@ + ToJsonb::class, + ]; + } + + protected function getExpectedSqlStatements(): array + { + return [ + 'SELECT to_jsonb(c0_.text) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_jsonb(UPPER(c0_.text)) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_jsonb(1 + 1) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_jsonb(1) AS sclr_0 FROM ContainsText c0_', + 'SELECT to_jsonb(LENGTH(c0_.text)) AS sclr_0 FROM ContainsText c0_', + ]; + } + + protected function getDqlStatements(): array + { + return [ + \sprintf('SELECT TO_JSONB(e.text) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_JSONB(UPPER(e.text)) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_JSONB(1+1) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_JSONB(true) FROM %s e', ContainsText::class), + \sprintf('SELECT TO_JSONB(LENGTH(e.text)) FROM %s e', ContainsText::class), + ]; + } +} diff --git a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsqueryTest.php b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsqueryTest.php index 15d8eae9..546c41e5 100644 --- a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsqueryTest.php +++ b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsqueryTest.php @@ -21,9 +21,6 @@ protected function getExpectedSqlStatements(): array return [ 'SELECT to_tsquery(c0_.text) AS sclr_0 FROM ContainsText c0_', 'SELECT to_tsquery(UPPER(c0_.text)) AS sclr_0 FROM ContainsText c0_', - 'SELECT to_tsquery(1 + 1) AS sclr_0 FROM ContainsText c0_', - 'SELECT to_tsquery(1) AS sclr_0 FROM ContainsText c0_', - 'SELECT to_tsquery(LENGTH(c0_.text)) AS sclr_0 FROM ContainsText c0_', ]; } @@ -32,9 +29,6 @@ protected function getDqlStatements(): array return [ \sprintf('SELECT TO_TSQUERY(e.text) FROM %s e', ContainsText::class), \sprintf('SELECT TO_TSQUERY(UPPER(e.text)) FROM %s e', ContainsText::class), - \sprintf('SELECT TO_TSQUERY(1+1) FROM %s e', ContainsText::class), - \sprintf('SELECT TO_TSQUERY(true) FROM %s e', ContainsText::class), - \sprintf('SELECT TO_TSQUERY(LENGTH(e.text)) FROM %s e', ContainsText::class), ]; } } diff --git a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php index fcf09e59..e265ae32 100644 --- a/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php +++ b/tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvectorTest.php @@ -21,9 +21,6 @@ protected function getExpectedSqlStatements(): array return [ 'SELECT to_tsvector(c0_.text) AS sclr_0 FROM ContainsText c0_', 'SELECT to_tsvector(LOWER(c0_.text)) AS sclr_0 FROM ContainsText c0_', - 'SELECT to_tsvector(1 + 1) AS sclr_0 FROM ContainsText c0_', - 'SELECT to_tsvector(1) AS sclr_0 FROM ContainsText c0_', - 'SELECT to_tsvector(LENGTH(c0_.text)) AS sclr_0 FROM ContainsText c0_', ]; } @@ -32,9 +29,6 @@ protected function getDqlStatements(): array return [ \sprintf('SELECT TO_TSVECTOR(e.text) FROM %s e', ContainsText::class), \sprintf('SELECT TO_TSVECTOR(LOWER(e.text)) FROM %s e', ContainsText::class), - \sprintf('SELECT TO_TSVECTOR(1+1) FROM %s e', ContainsText::class), - \sprintf('SELECT TO_TSVECTOR(true) FROM %s e', ContainsText::class), - \sprintf('SELECT TO_TSVECTOR(LENGTH(e.text)) FROM %s e', ContainsText::class), ]; } } From 6a5cd8d9206c061345e2d5787bd0eff24c509784 Mon Sep 17 00:00:00 2001 From: Magnus Nordlander Date: Wed, 29 May 2019 16:59:16 +0200 Subject: [PATCH 6/6] Fixed undo change --- .../Doctrine/ORM/Query/AST/Functions/ToTsvector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvector.php b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvector.php index e0276f27..d504e0cd 100644 --- a/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvector.php +++ b/src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ToTsvector.php @@ -17,6 +17,6 @@ class ToTsvector extends BaseFunction protected function customiseFunction(): void { $this->setFunctionPrototype('to_tsvector(%s)'); - $this->addNodeMapping('StringPrimary'); + $this->addNodeMapping('StringExpression'); } }