-
-
Notifications
You must be signed in to change notification settings - Fork 56
feat: add the ability to specify range bounds #371
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||||||||
| <?php | ||||||||||||
|
|
||||||||||||
| declare(strict_types=1); | ||||||||||||
|
|
||||||||||||
| namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * @see https://www.postgresql.org/docs/17/rangetypes.html | ||||||||||||
| * @since 3.1 | ||||||||||||
| * | ||||||||||||
| * @author Jan Klan <jan@klan.com.au> | ||||||||||||
| */ | ||||||||||||
| abstract class BaseRangeFunction extends BaseVariadicFunction | ||||||||||||
| { | ||||||||||||
| protected function getNodeMappingPattern(): array | ||||||||||||
| { | ||||||||||||
| return [ | ||||||||||||
| 'ArithmeticPrimary', | ||||||||||||
| 'ArithmeticPrimary', | ||||||||||||
| 'StringPrimary', | ||||||||||||
|
Comment on lines
+18
to
+20
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| ]; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| protected function getMinArgumentCount(): int | ||||||||||||
| { | ||||||||||||
| return 2; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| protected function getMaxArgumentCount(): int | ||||||||||||
| { | ||||||||||||
| return 3; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,12 +12,19 @@ | |||||||||
| * | ||||||||||
| * @author Martin Georgiev <martin.georgiev@gmail.com> | ||||||||||
| */ | ||||||||||
| class Daterange extends BaseFunction | ||||||||||
| class Daterange extends BaseRangeFunction | ||||||||||
| { | ||||||||||
| protected function customizeFunction(): void | ||||||||||
| protected function getFunctionName(): string | ||||||||||
| { | ||||||||||
| $this->setFunctionPrototype('daterange(%s, %s)'); | ||||||||||
| $this->addNodeMapping('StringPrimary'); | ||||||||||
| $this->addNodeMapping('StringPrimary'); | ||||||||||
| return 'daterange'; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| protected function getNodeMappingPattern(): array | ||||||||||
| { | ||||||||||
| return [ | ||||||||||
| 'StringPrimary', | ||||||||||
| 'StringPrimary', | ||||||||||
| 'StringPrimary', | ||||||||||
|
Comment on lines
+25
to
+27
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| ]; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,12 +12,19 @@ | |||||||||
| * | ||||||||||
| * @author Martin Georgiev <martin.georgiev@gmail.com> | ||||||||||
| */ | ||||||||||
| class Tsrange extends BaseFunction | ||||||||||
| class Tsrange extends BaseRangeFunction | ||||||||||
| { | ||||||||||
| protected function customizeFunction(): void | ||||||||||
| protected function getFunctionName(): string | ||||||||||
| { | ||||||||||
| $this->setFunctionPrototype('tsrange(%s, %s)'); | ||||||||||
| $this->addNodeMapping('StringPrimary'); | ||||||||||
| $this->addNodeMapping('StringPrimary'); | ||||||||||
| return 'tsrange'; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| protected function getNodeMappingPattern(): array | ||||||||||
| { | ||||||||||
| return [ | ||||||||||
| 'StringPrimary', | ||||||||||
| 'StringPrimary', | ||||||||||
| 'StringPrimary', | ||||||||||
|
Comment on lines
+25
to
+27
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @coderabbitai - does this look alright to you? Analyse the usage of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain@martin-georgiev I've analyzed the usage of The code in However, I noticed an inconsistency:
This means Would you like me to provide a code suggestion for the (_/) 🏁 Script executed: Length of output: 2443 🏁 Script executed: Length of output: 2125 🏁 Script executed: Length of output: 853 🏁 Script executed: Length of output: 822 🌐 Web query: 💡 Result: PostgreSQL's Function Signature and ParametersThe
Where:
Usage ExamplesThe -- Create a reservation table using tsrange
CREATE TABLE reservation (
room int,
during tsrange
);
-- Insert a reservation for a specific time period
INSERT INTO reservation VALUES (1108, '[2010-01-01 14:30, 2010-01-01 15:30)');You can also query records that fall within a specific time range: -- Select orders created within a specific time range
SELECT * FROM orders
WHERE created_at <@ tsrange('2023-03-14 04:00:00', '2023-03-14 10:00:00');PostgreSQL also provides a corresponding multirange type called Citations:
@martin-georgiev I've analyzed the usage of The implementation looks correct for the following reasons:
This implementation correctly handles PostgreSQL's range function signatures, including the optional third parameter for specifying bounds. No revisions appear necessary for the current PR. 🧬 Code Graph Analysis ResultsRelevant snippets for analyzing
|
||||||||||
| 'StringPrimary', | |
| 'StringPrimary', | |
| 'StringPrimary', | |
| 'StringPrimary', |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,12 +12,19 @@ | |||||||||
| * | ||||||||||
| * @author Martin Georgiev <martin.georgiev@gmail.com> | ||||||||||
| */ | ||||||||||
| class Tstzrange extends BaseFunction | ||||||||||
| class Tstzrange extends BaseRangeFunction | ||||||||||
| { | ||||||||||
| protected function customizeFunction(): void | ||||||||||
| protected function getFunctionName(): string | ||||||||||
| { | ||||||||||
| $this->setFunctionPrototype('tstzrange(%s, %s)'); | ||||||||||
| $this->addNodeMapping('StringPrimary'); | ||||||||||
| $this->addNodeMapping('StringPrimary'); | ||||||||||
| return 'tstzrange'; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| protected function getNodeMappingPattern(): array | ||||||||||
| { | ||||||||||
| return [ | ||||||||||
| 'StringPrimary', | ||||||||||
| 'StringPrimary', | ||||||||||
| 'StringPrimary', | ||||||||||
|
Comment on lines
+25
to
+27
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| ]; | ||||||||||
| } | ||||||||||
| } | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.