Skip to content

Commit 255144d

Browse files
feat: add support for specifying explicit range bounds
1 parent 8b2bdee commit 255144d

File tree

12 files changed

+150
-42
lines changed

12 files changed

+150
-42
lines changed

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Daterange.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,28 @@
1212
*
1313
* @author Martin Georgiev <martin.georgiev@gmail.com>
1414
*/
15-
class Daterange extends BaseFunction
15+
class Daterange extends BaseVariadicFunction
1616
{
17-
protected function customizeFunction(): void
17+
protected function getFunctionName(): string
1818
{
19-
$this->setFunctionPrototype('daterange(%s, %s)');
20-
$this->addNodeMapping('StringPrimary');
21-
$this->addNodeMapping('StringPrimary');
19+
return 'daterange';
20+
}
21+
22+
/**
23+
* @return array<string>
24+
*/
25+
protected function getNodeMappingPattern(): array
26+
{
27+
return ['StringPrimary'];
28+
}
29+
30+
protected function getMinArgumentCount(): int
31+
{
32+
return 2;
33+
}
34+
35+
protected function getMaxArgumentCount(): int
36+
{
37+
return 3;
2238
}
2339
}

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Int4range.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,28 @@
1212
*
1313
* @author Martin Georgiev <martin.georgiev@gmail.com>
1414
*/
15-
class Int4range extends BaseFunction
15+
class Int4range extends BaseVariadicFunction
1616
{
17-
protected function customizeFunction(): void
17+
protected function getFunctionName(): string
1818
{
19-
$this->setFunctionPrototype('int4range(%s, %s)');
20-
$this->addNodeMapping('StringPrimary');
21-
$this->addNodeMapping('StringPrimary');
19+
return 'int4range';
20+
}
21+
22+
/**
23+
* @return array<string>
24+
*/
25+
protected function getNodeMappingPattern(): array
26+
{
27+
return ['StringPrimary'];
28+
}
29+
30+
protected function getMinArgumentCount(): int
31+
{
32+
return 2;
33+
}
34+
35+
protected function getMaxArgumentCount(): int
36+
{
37+
return 3;
2238
}
2339
}

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Int8range.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,28 @@
1212
*
1313
* @author Martin Georgiev <martin.georgiev@gmail.com>
1414
*/
15-
class Int8range extends BaseFunction
15+
class Int8range extends BaseVariadicFunction
1616
{
17-
protected function customizeFunction(): void
17+
protected function getFunctionName(): string
1818
{
19-
$this->setFunctionPrototype('int8range(%s, %s)');
20-
$this->addNodeMapping('StringPrimary');
21-
$this->addNodeMapping('StringPrimary');
19+
return 'int8range';
20+
}
21+
22+
/**
23+
* @return array<string>
24+
*/
25+
protected function getNodeMappingPattern(): array
26+
{
27+
return ['StringPrimary'];
28+
}
29+
30+
protected function getMinArgumentCount(): int
31+
{
32+
return 2;
33+
}
34+
35+
protected function getMaxArgumentCount(): int
36+
{
37+
return 3;
2238
}
2339
}

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Numrange.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,28 @@
1212
*
1313
* @author Martin Georgiev <martin.georgiev@gmail.com>
1414
*/
15-
class Numrange extends BaseFunction
15+
class Numrange extends BaseVariadicFunction
1616
{
17-
protected function customizeFunction(): void
17+
protected function getFunctionName(): string
1818
{
19-
$this->setFunctionPrototype('numrange(%s, %s)');
20-
$this->addNodeMapping('StringPrimary');
21-
$this->addNodeMapping('StringPrimary');
19+
return 'numrange';
20+
}
21+
22+
/**
23+
* @return array<string>
24+
*/
25+
protected function getNodeMappingPattern(): array
26+
{
27+
return ['StringPrimary'];
28+
}
29+
30+
protected function getMinArgumentCount(): int
31+
{
32+
return 2;
33+
}
34+
35+
protected function getMaxArgumentCount(): int
36+
{
37+
return 3;
2238
}
2339
}

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Tsrange.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,28 @@
1212
*
1313
* @author Martin Georgiev <martin.georgiev@gmail.com>
1414
*/
15-
class Tsrange extends BaseFunction
15+
class Tsrange extends BaseVariadicFunction
1616
{
17-
protected function customizeFunction(): void
17+
protected function getFunctionName(): string
1818
{
19-
$this->setFunctionPrototype('tsrange(%s, %s)');
20-
$this->addNodeMapping('StringPrimary');
21-
$this->addNodeMapping('StringPrimary');
19+
return 'tsrange';
20+
}
21+
22+
/**
23+
* @return array<string>
24+
*/
25+
protected function getNodeMappingPattern(): array
26+
{
27+
return ['StringPrimary'];
28+
}
29+
30+
protected function getMinArgumentCount(): int
31+
{
32+
return 2;
33+
}
34+
35+
protected function getMaxArgumentCount(): int
36+
{
37+
return 3;
2238
}
2339
}

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Tstzrange.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,28 @@
1212
*
1313
* @author Martin Georgiev <martin.georgiev@gmail.com>
1414
*/
15-
class Tstzrange extends BaseFunction
15+
class Tstzrange extends BaseVariadicFunction
1616
{
17-
protected function customizeFunction(): void
17+
protected function getFunctionName(): string
1818
{
19-
$this->setFunctionPrototype('tstzrange(%s, %s)');
20-
$this->addNodeMapping('StringPrimary');
21-
$this->addNodeMapping('StringPrimary');
19+
return 'tstzrange';
20+
}
21+
22+
/**
23+
* @return array<string>
24+
*/
25+
protected function getNodeMappingPattern(): array
26+
{
27+
return ['StringPrimary'];
28+
}
29+
30+
protected function getMinArgumentCount(): int
31+
{
32+
return 2;
33+
}
34+
35+
protected function getMaxArgumentCount(): int
36+
{
37+
return 3;
2238
}
2339
}

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DaterangeTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ protected function getStringFunctions(): array
1919
protected function getExpectedSqlStatements(): array
2020
{
2121
return [
22-
'SELECT daterange(c0_.date1, c0_.date2) AS sclr_0 FROM ContainsDates c0_',
22+
'basic range with default bounds' => 'SELECT daterange(c0_.date1, c0_.date2) AS sclr_0 FROM ContainsDates c0_',
23+
'range with explicit bounds' => "SELECT daterange(c0_.date1, c0_.date2, '[)') AS sclr_0 FROM ContainsDates c0_",
2324
];
2425
}
2526

2627
protected function getDqlStatements(): array
2728
{
2829
return [
29-
\sprintf('SELECT DATERANGE(e.date1, e.date2) FROM %s e', ContainsDates::class),
30+
'basic range with default bounds' => \sprintf('SELECT DATERANGE(e.date1, e.date2) FROM %s e', ContainsDates::class),
31+
'range with explicit bounds' => \sprintf("SELECT DATERANGE(e.date1, e.date2, '[)') FROM %s e", ContainsDates::class),
3032
];
3133
}
3234
}

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Int4rangeTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ protected function getStringFunctions(): array
1919
protected function getExpectedSqlStatements(): array
2020
{
2121
return [
22-
'SELECT int4range(c0_.integer1, c0_.integer2) AS sclr_0 FROM ContainsIntegers c0_',
22+
'basic range with default bounds' => 'SELECT int4range(c0_.integer1, c0_.integer2) AS sclr_0 FROM ContainsIntegers c0_',
23+
'range with explicit bounds' => "SELECT int4range(c0_.integer1, c0_.integer2, '[)') AS sclr_0 FROM ContainsIntegers c0_",
2324
];
2425
}
2526

2627
protected function getDqlStatements(): array
2728
{
2829
return [
29-
\sprintf('SELECT INT4RANGE(e.integer1, e.integer2) FROM %s e', ContainsIntegers::class),
30+
'basic range with default bounds' => \sprintf('SELECT INT4RANGE(e.integer1, e.integer2) FROM %s e', ContainsIntegers::class),
31+
'range with explicit bounds' => \sprintf("SELECT INT4RANGE(e.integer1, e.integer2, '[)') FROM %s e", ContainsIntegers::class),
3032
];
3133
}
3234
}

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Int8rangeTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ protected function getStringFunctions(): array
1919
protected function getExpectedSqlStatements(): array
2020
{
2121
return [
22-
'SELECT int8range(c0_.integer1, c0_.integer2) AS sclr_0 FROM ContainsIntegers c0_',
22+
'basic range with default bounds' => 'SELECT int8range(c0_.integer1, c0_.integer2) AS sclr_0 FROM ContainsIntegers c0_',
23+
'range with explicit bounds' => "SELECT int8range(c0_.integer1, c0_.integer2, '[)') AS sclr_0 FROM ContainsIntegers c0_",
2324
];
2425
}
2526

2627
protected function getDqlStatements(): array
2728
{
2829
return [
29-
\sprintf('SELECT INT8RANGE(e.integer1, e.integer2) FROM %s e', ContainsIntegers::class),
30+
'basic range with default bounds' => \sprintf('SELECT INT8RANGE(e.integer1, e.integer2) FROM %s e', ContainsIntegers::class),
31+
'range with explicit bounds' => \sprintf("SELECT INT8RANGE(e.integer1, e.integer2, '[)') FROM %s e", ContainsIntegers::class),
3032
];
3133
}
3234
}

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/NumrangeTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ protected function getStringFunctions(): array
1919
protected function getExpectedSqlStatements(): array
2020
{
2121
return [
22-
'SELECT numrange(c0_.decimal1, c0_.decimal2) AS sclr_0 FROM ContainsDecimals c0_',
22+
'basic range with default bounds' => 'SELECT numrange(c0_.decimal1, c0_.decimal2) AS sclr_0 FROM ContainsDecimals c0_',
23+
'range with explicit bounds' => "SELECT numrange(c0_.decimal1, c0_.decimal2, '[)') AS sclr_0 FROM ContainsDecimals c0_",
2324
];
2425
}
2526

2627
protected function getDqlStatements(): array
2728
{
2829
return [
29-
\sprintf('SELECT NUMRANGE(e.decimal1, e.decimal2) FROM %s e', ContainsDecimals::class),
30+
'basic range with default bounds' => \sprintf('SELECT NUMRANGE(e.decimal1, e.decimal2) FROM %s e', ContainsDecimals::class),
31+
'range with explicit bounds' => \sprintf("SELECT NUMRANGE(e.decimal1, e.decimal2, '[)') FROM %s e", ContainsDecimals::class),
3032
];
3133
}
3234
}

0 commit comments

Comments
 (0)