Skip to content

feat: add support for range types #396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Enhances Doctrine with PostgreSQL-specific features and functions. Supports Post
// Register types with Doctrine
Type::addType('jsonb', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\Jsonb");
Type::addType('text[]', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\TextArray");
Type::addType('numrange', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\NumRange");

// Use in your Doctrine entities
#[ORM\Column(type: 'jsonb')]
Expand All @@ -21,6 +22,9 @@ private array $data;
#[ORM\Column(type: 'text[]')]
private array $tags;

#[ORM\Column(type: 'numrange')]
private NumericRange $priceRange;

// Use in DQL
$query = $em->createQuery('
SELECT e
Expand Down Expand Up @@ -51,6 +55,9 @@ This package provides comprehensive Doctrine support for PostgreSQL features:
- MAC addresses (`macaddr`, `macaddr[]`)
- **Geometric Types**
- Point (`point`, `point[]`)
- **Range Types**
- Date and time ranges (`daterange`, `tsrange`, `tstzrange`)
- Numeric ranges (`numrange`, `int4range`, `int8range`)

### PostgreSQL Operators
- **Array Operations**
Expand All @@ -62,6 +69,9 @@ This package provides comprehensive Doctrine support for PostgreSQL features:
- Field access (`->`, `->>`)
- Path operations (`#>`, `#>>`)
- JSON containment and existence operators
- **Range Operations**
- Containment checks (in PHP value objects and for DQL queries with `@>`)
- Overlaps (`&&`)

### Functions
- **Text Search**
Expand All @@ -85,6 +95,7 @@ This package provides comprehensive Doctrine support for PostgreSQL features:

Full documentation:
- [Available Types](docs/AVAILABLE-TYPES.md)
- [Value Objects for Range Types](docs/RANGE-TYPES.md)
- [Available Functions and Operators](docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md)
- [Common Use Cases and Examples](docs/USE-CASES-AND-EXAMPLES.md)

Expand Down
25 changes: 25 additions & 0 deletions ci/phpstan/baselines/range-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
parameters:
ignoreErrors:
-
message: '#^Method MartinGeorgiev\\Doctrine\\DBAL\\Types\\ValueObject\\Range\:\:empty\(\) should return static\(MartinGeorgiev\\Doctrine\\DBAL\\Types\\ValueObject\\Range\<R of DateTimeInterface\|float\|int\>\) but returns static\(MartinGeorgiev\\Doctrine\\DBAL\\Types\\ValueObject\\Range\<DateTimeInterface\|float\|int\>\)\.$#'
identifier: return.type
count: 1
path: ../../../src/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/Range.php

-
message: '#^Method MartinGeorgiev\\Doctrine\\DBAL\\Types\\ValueObject\\Range\:\:fromString\(\) should return static\(MartinGeorgiev\\Doctrine\\DBAL\\Types\\ValueObject\\Range\<R of DateTimeInterface\|float\|int\>\) but returns static\(MartinGeorgiev\\Doctrine\\DBAL\\Types\\ValueObject\\Range\<DateTimeInterface\|float\|int\>\)\.$#'
identifier: return.type
count: 2
path: ../../../src/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/Range.php

-
message: '#^Method MartinGeorgiev\\Doctrine\\DBAL\\Types\\ValueObject\\Range\:\:infinite\(\) should return static\(MartinGeorgiev\\Doctrine\\DBAL\\Types\\ValueObject\\Range\<R of DateTimeInterface\|float\|int\>\) but returns static\(MartinGeorgiev\\Doctrine\\DBAL\\Types\\ValueObject\\Range\<DateTimeInterface\|float\|int\>\)\.$#'
identifier: return.type
count: 1
path: ../../../src/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/Range.php

-
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: new.static
count: 4
path: ../../../src/MartinGeorgiev/Doctrine/DBAL/Types/ValueObject/Range.php
1 change: 1 addition & 0 deletions ci/phpstan/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ includes:
- ./baselines/deprecated-methods.neon
- ./baselines/lexer-variations.neon
- ./baselines/phpstan-identifiers.neon
- ./baselines/range-baseline.neon
- ./baselines/type-mismatches.neon

parameters:
Expand Down
6 changes: 6 additions & 0 deletions docs/AVAILABLE-TYPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@
| macaddr[] | _macaddr | `MartinGeorgiev\Doctrine\DBAL\Types\MacaddrArray` |
| point | point | `MartinGeorgiev\Doctrine\DBAL\Types\Point` |
| point[] | _point | `MartinGeorgiev\Doctrine\DBAL\Types\PointArray` |
| daterange | daterange | `MartinGeorgiev\Doctrine\DBAL\Types\DateRange` |
| int4range | int4range | `MartinGeorgiev\Doctrine\DBAL\Types\Int4Range` |
| int8range | int8range | `MartinGeorgiev\Doctrine\DBAL\Types\Int8Range` |
| numrange | numrange | `MartinGeorgiev\Doctrine\DBAL\Types\NumRange` |
| tsrange | tsrange | `MartinGeorgiev\Doctrine\DBAL\Types\TsRange` |
| tstzrange | tstzrange | `MartinGeorgiev\Doctrine\DBAL\Types\TstzRange` |
14 changes: 14 additions & 0 deletions docs/INTEGRATING-WITH-DOCTRINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ Type::addType('macaddr[]', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\MacaddrArray"

Type::addType('point', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\Point");
Type::addType('point[]', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\PointArray");

Type::addType('daterange', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\DateRange");
Type::addType('int4range', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\Int4Range");
Type::addType('int8range', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\Int8Range");
Type::addType('numrange', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\NumRange");
Type::addType('tsrange', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\TsRange");
Type::addType('tstzrange', "MartinGeorgiev\\Doctrine\\DBAL\\Types\\TstzRange");
```


Expand Down Expand Up @@ -237,6 +244,13 @@ $platform->registerDoctrineTypeMapping('_macaddr','macaddr[]');
$platform->registerDoctrineTypeMapping('point','point');
$platform->registerDoctrineTypeMapping('point[]','point[]');
$platform->registerDoctrineTypeMapping('_point','point[]');

$platform->registerDoctrineTypeMapping('daterange','daterange');
$platform->registerDoctrineTypeMapping('int4range','int4range');
$platform->registerDoctrineTypeMapping('int8range','int8range');
$platform->registerDoctrineTypeMapping('numrange','numrange');
$platform->registerDoctrineTypeMapping('tsrange','tsrange');
$platform->registerDoctrineTypeMapping('tstzrange','tstzrange');
...

```
Loading
Loading