From 50b79c1b2b13b02e08ff5890f4c6f1fc890a27b0 Mon Sep 17 00:00:00 2001 From: Moath Date: Sat, 30 Oct 2021 17:58:49 +0300 Subject: [PATCH] add `rawQuery` function --- README.md | 8 ++++++++ src/Jql.php | 5 +++++ tests/JqlTest.php | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/README.md b/README.md index c890f58..85bbdfa 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,14 @@ generate query conditions based on your condition: ->getQuery(); // "project = 'MY PROJECT'" ``` +generate query using raw query: + +```php +\DevMoath\JqlBuilder\Jql::query() + ->rawQuery("project = 'MY PROJECT' order by created asc") + ->getQuery(); // "project = 'MY PROJECT' order by created asc" +``` + Also, you can add macro functions as well: ```php diff --git a/src/Jql.php b/src/Jql.php index 358f06e..07ae2c6 100644 --- a/src/Jql.php +++ b/src/Jql.php @@ -152,6 +152,11 @@ public function orderBy(string $column, string $direction): self return tap($this, fn() => $this->appendQuery(self::ORDER_BY." $column $direction")); } + public function rawQuery(string $query): self + { + return tap($this, fn() => $this->appendQuery($query)); + } + public function getQuery(): string { return trim($this->query); diff --git a/tests/JqlTest.php b/tests/JqlTest.php index af77f90..5e57eb9 100644 --- a/tests/JqlTest.php +++ b/tests/JqlTest.php @@ -64,6 +64,16 @@ public function it_can_generate_query_conditions_based_on_your_condition(): void self::assertSame("project = 'MY PROJECT'", $query); } + /** @test */ + public function it_can_generate_query_using_raw_query(): void + { + $query = Jql::query() + ->rawQuery("project = 'MY PROJECT' order by created asc") + ->getQuery(); + + self::assertSame("project = 'MY PROJECT' order by created asc", $query); + } + /** @test */ public function it_can_add_macro(): void {