Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ This package provides comprehensive Doctrine support for PostgreSQL features:
- **Aggregate Functions**
- Aggregation with ordering and distinct (`array_agg`, `json_agg`, `jsonb_agg`)
- Special aggregates (`any_value`, `xmlagg`)
- **Mathematical/Arithmetic Functions**
- CBRT, CEIL, DEGREES, EXP, FLOOR, LN, LOG, PI, POWER, RADIANS, RANDOM, ROUND, SIGN, TRUNC, WIDTH_BUCKET
- **Range Functions**
- DATERANGE, INT4RANGE, INT8RANGE, NUMRANGE, TSRANGE, TSTZRANGE

Full documentation:
- [Available Types](docs/AVAILABLE-TYPES.md)
Expand Down
12 changes: 11 additions & 1 deletion docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

| PostgreSQL functions | Register for DQL as | Implemented by
|---|---|---|
| abs | ABS | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Abs` |
| all | ALL_OF | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\All` |
| any | ANY_OF | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Any` |
| any_value | ANY_VALUE | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\AnyValue` |
Expand Down Expand Up @@ -118,6 +117,17 @@
| unaccent | UNACCENT | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Unaccent` |
| unnest | UNNEST | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Unnest` |
| xmlagg | XML_AGG | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\XmlAgg` |
| cbrt | CBRT | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Cbrt` |
| degrees | DEGREES | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Degrees` |
| exp | EXP | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exp` |
| ln | LN | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Ln` |
| log | LOG | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Log` |
| pi | PI | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Pi` |
| power | POWER | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Power` |
| radians | RADIANS | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Radians` |
| random | RANDOM | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Random` |
| sign | SIGN | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Sign` |
| width_bucket | WIDTH_BUCKET | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\WidthBucket` |


# Bonus helpers
Expand Down
12 changes: 11 additions & 1 deletion docs/INTEGRATING-WITH-DOCTRINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,21 @@ $configuration->addCustomStringFunction('TSRANGE', MartinGeorgiev\Doctrine\ORM\Q
$configuration->addCustomStringFunction('TSTZRANGE', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Tstzrange::class);

# Arithmetic functions
$configuration->addCustomStringFunction('ABS', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Abs::class);
$configuration->addCustomStringFunction('CBRT', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Cbrt::class);
$configuration->addCustomStringFunction('CEIL', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Ceil::class);
$configuration->addCustomStringFunction('DEGREES', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Degrees::class);
$configuration->addCustomStringFunction('EXP', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exp::class);
$configuration->addCustomStringFunction('FLOOR', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Floor::class);
$configuration->addCustomStringFunction('LN', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Ln::class);
$configuration->addCustomStringFunction('LOG', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Log::class);
$configuration->addCustomStringFunction('PI', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Pi::class);
$configuration->addCustomStringFunction('POWER', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Power::class);
$configuration->addCustomStringFunction('RADIANS', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Radians::class);
$configuration->addCustomStringFunction('RANDOM', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Random::class);
$configuration->addCustomStringFunction('ROUND', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Round::class);
$configuration->addCustomStringFunction('SIGN', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Sign::class);
$configuration->addCustomStringFunction('TRUNC', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Trunc::class);
$configuration->addCustomStringFunction('WIDTH_BUCKET', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\WidthBucket::class);

# other operators
$configuration->addCustomStringFunction('CAST', MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Cast::class);
Expand Down
12 changes: 11 additions & 1 deletion docs/INTEGRATING-WITH-LARAVEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,21 @@ return [
'TSTZRANGE' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Tstzrange::class,

# Arithmetic functions
'ABS' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Abs::class,
'CBRT' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Cbrt::class,
'CEIL' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Ceil::class,
'DEGREES' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Degrees::class,
'EXP' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exp::class,
'FLOOR' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Floor::class,
'LN' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Ln::class,
'LOG' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Log::class,
'PI' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Pi::class,
'POWER' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Power::class,
'RADIANS' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Radians::class,
'RANDOM' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Random::class,
'ROUND' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Round::class,
'SIGN' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Sign::class,
'TRUNC' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Trunc::class,
'WIDTH_BUCKET' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\WidthBucket::class,

# other operators
'CAST' => MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Cast::class,
Expand Down
12 changes: 11 additions & 1 deletion docs/INTEGRATING-WITH-SYMFONY.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,21 @@ doctrine:
TSTZRANGE: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Tstzrange

# Arithmetic functions
ABS: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Abs
CBRT: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Cbrt
CEIL: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Ceil
DEGREES: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Degrees
EXP: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exp
FLOOR: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Floor
LN: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Ln
LOG: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Log
PI: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Pi
POWER: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Power
RADIANS: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Radians
RANDOM: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Random
ROUND: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Round
SIGN: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Sign
TRUNC: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Trunc
WIDTH_BUCKET: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\WidthBucket

# other operators
CAST: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Cast
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Implementation of PostgreSQL ARRAY_SHUFFLE().
*
* @see https://www.postgresql.org/docs/current/functions-array.html
* @see https://www.postgresql.org/docs/17/functions-array.html
* @since 3.0
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
Expand Down
21 changes: 21 additions & 0 deletions src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cbrt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSQL CBRT() - cube root.
*
* @see https://www.postgresql.org/docs/17/functions-math.html
* @since 3.2
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class Cbrt extends BaseArithmeticFunction
{
protected function getFunctionName(): string
{
return 'CBRT';
}
}
21 changes: 21 additions & 0 deletions src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Degrees.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSQL DEGREES() - converts radians to degrees.
*
* @see https://www.postgresql.org/docs/17/functions-math.html
* @since 3.2
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class Degrees extends BaseArithmeticFunction
{
protected function getFunctionName(): string
{
return 'DEGREES';
}
}
21 changes: 21 additions & 0 deletions src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Exp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSQL EXP() - exponential function (e^x).
*
* @see https://www.postgresql.org/docs/17/functions-math.html
* @since 3.2
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class Exp extends BaseArithmeticFunction
{
protected function getFunctionName(): string
{
return 'EXP';
}
}
21 changes: 21 additions & 0 deletions src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Ln.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSQL LN() - natural logarithm.
*
* @see https://www.postgresql.org/docs/17/functions-math.html
* @since 3.2
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class Ln extends BaseArithmeticFunction
{
protected function getFunctionName(): string
{
return 'LN';
}
}
31 changes: 31 additions & 0 deletions src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSQL LOG() - logarithm with specified base.
*
* @see https://www.postgresql.org/docs/17/functions-math.html
* @since 3.2
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class Log extends BaseArithmeticFunction
{
protected function getFunctionName(): string
{
return 'LOG';
}

protected function getMaxArgumentCount(): int
{
return 2;
}

protected function getMinArgumentCount(): int
{
return 2;
}
}
31 changes: 31 additions & 0 deletions src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Pi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSQL PI() - returns the mathematical constant π.
*
* @see https://www.postgresql.org/docs/17/functions-math.html
* @since 3.2
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class Pi extends BaseArithmeticFunction
{
protected function getFunctionName(): string
{
return 'PI';
}

protected function getMaxArgumentCount(): int
{
return 0; // PI() takes no arguments
}

protected function getMinArgumentCount(): int
{
return 0; // PI() takes no arguments
}
}
31 changes: 31 additions & 0 deletions src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Power.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSQL POWER() function.
*
* @see https://www.postgresql.org/docs/17/functions-math.html
* @since 3.2
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class Power extends BaseArithmeticFunction
{
protected function getFunctionName(): string
{
return 'POWER';
}

protected function getMaxArgumentCount(): int
{
return 2;
}

protected function getMinArgumentCount(): int
{
return 2;
}
}
21 changes: 21 additions & 0 deletions src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Radians.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSQL RADIANS() - converts degrees to radians.
*
* @see https://www.postgresql.org/docs/17/functions-math.html
* @since 3.2
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class Radians extends BaseArithmeticFunction
{
protected function getFunctionName(): string
{
return 'RADIANS';
}
}
31 changes: 31 additions & 0 deletions src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Random.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSQL RANDOM() - returns a random value between 0.0 and 1.0.
*
* @see https://www.postgresql.org/docs/17/functions-math.html
* @since 3.2
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class Random extends BaseArithmeticFunction
{
protected function getFunctionName(): string
{
return 'RANDOM';
}

protected function getMaxArgumentCount(): int
{
return 0; // RANDOM() takes no arguments
}

protected function getMinArgumentCount(): int
{
return 0; // RANDOM() takes no arguments
}
}
21 changes: 21 additions & 0 deletions src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Sign.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSQL SIGN().
*
* @see https://www.postgresql.org/docs/17/functions-math.html
* @since 3.2
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class Sign extends BaseArithmeticFunction
{
protected function getFunctionName(): string
{
return 'SIGN';
}
}
Loading
Loading