From a4f96b9393554924a2965729aabaf93f477d7ae0 Mon Sep 17 00:00:00 2001 From: laise Date: Tue, 31 Dec 2024 09:55:42 -0300 Subject: [PATCH 1/2] feat: add is null and not null to iteratorSqlFormatter --- src/IteratorFilterSqlFormatter.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/IteratorFilterSqlFormatter.php b/src/IteratorFilterSqlFormatter.php index e6a1146..1866b09 100644 --- a/src/IteratorFilterSqlFormatter.php +++ b/src/IteratorFilterSqlFormatter.php @@ -87,6 +87,12 @@ public function getRelation(string $name, Relation $relation, mixed $value, arra } return " $name NOT IN ($placeholders) "; }, + Relation::IS_NULL => function (&$param, $name, $paramName, $value) { + return " $name IS NULL "; + }, + Relation::IS_NOT_NULL => function (&$param, $name, $paramName, $value) { + return " $name IS NOT NULL "; + }, }; return $data($param, $name, $paramName, $value); } From 072b0f40623bd6ebc7c837b11f995edbc52a4b40 Mon Sep 17 00:00:00 2001 From: laise Date: Tue, 31 Dec 2024 13:08:02 -0300 Subject: [PATCH 2/2] feat: add tests for relation is null and is not null --- tests/IteratorFilterTest.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/IteratorFilterTest.php b/tests/IteratorFilterTest.php index c549d3b..8d335bd 100644 --- a/tests/IteratorFilterTest.php +++ b/tests/IteratorFilterTest.php @@ -151,6 +151,40 @@ public function testAddRelationOr() $this->assertEquals('select * from tablename where field = :field or field2 = :field2 ', $sql); } + public function testRelationIsNull() + { + $this->object->and('field', Relation::IS_NULL, null); + + $params = []; + $returnFields = '*'; + $sql = $this->object->format( + new IteratorFilterSqlFormatter(), + 'tablename', + $params, + $returnFields + ); + + $this->assertEquals([], $params); + $this->assertEquals('select * from tablename where field IS NULL ', $sql); + } + + public function testRelationIsNotNull() + { + $this->object->and('field', Relation::IS_NOT_NULL, null); + + $params = []; + $returnFields = '*'; + $sql = $this->object->format( + new IteratorFilterSqlFormatter(), + 'tablename', + $params, + $returnFields + ); + + $this->assertEquals([], $params); + $this->assertEquals('select * from tablename where field IS NOT NULL ', $sql); + } + public function testGroup() { $this->object->startGroup();