From 9e99d8a48d8c6c0de51e2f2a0b6ec5f5b75bf548 Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Tue, 23 Jul 2024 13:10:41 +0200 Subject: [PATCH 1/7] fix: use actual namespace instead of alias --- src/Schema/Grammars/GrammarTable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Schema/Grammars/GrammarTable.php b/src/Schema/Grammars/GrammarTable.php index a10ea46..dc48f55 100644 --- a/src/Schema/Grammars/GrammarTable.php +++ b/src/Schema/Grammars/GrammarTable.php @@ -4,8 +4,8 @@ namespace Tpetry\PostgresqlEnhanced\Schema\Grammars; -use Arr; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Arr; use Illuminate\Support\Fluent; trait GrammarTable From 67a6b84d7ce8763581c34611141be61a29b5ed4b Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Wed, 24 Jul 2024 15:52:00 +0200 Subject: [PATCH 2/7] fix: adapt `whereLike` and `orWhereLike` to Laravel v11.17 --- src/Query/BuilderWhere.php | 8 ++++---- src/Query/GrammarWhere.php | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Query/BuilderWhere.php b/src/Query/BuilderWhere.php index 5bf84b0..18eaece 100644 --- a/src/Query/BuilderWhere.php +++ b/src/Query/BuilderWhere.php @@ -64,9 +64,9 @@ public function orWhereIntegerArrayMatches($column, string $query): static * @param Expression|string $column * @param Expression|string $value */ - public function orWhereLike($column, $value, bool $caseInsensitive = false): static + public function orWhereLike($column, $value, $caseSensitive = false): static { - return $this->whereLike($column, $value, $caseInsensitive, 'or'); + return $this->whereLike($column, $value, $caseSensitive, 'or', false); } /** @@ -183,11 +183,11 @@ public function whereIntegerArrayMatches($column, string $query): static * @param Expression|string $value * @param string $boolean */ - public function whereLike($column, $value, bool $caseInsensitive = false, $boolean = 'and'): static + public function whereLike($column, $value, $caseSensitive = false, $boolean = 'and', $not = false): static { $type = 'like'; - $this->wheres[] = compact('type', 'column', 'value', 'caseInsensitive', 'boolean'); + $this->wheres[] = compact('type', 'column', 'value', 'caseSensitive', 'boolean', 'not'); $this->addBinding($value); return $this; diff --git a/src/Query/GrammarWhere.php b/src/Query/GrammarWhere.php index 887d5d1..186f1be 100644 --- a/src/Query/GrammarWhere.php +++ b/src/Query/GrammarWhere.php @@ -46,14 +46,14 @@ public function whereAny(Builder $query, $where): string /** * Compile a "like" clause. * - * @param array{caseInsensitive: bool, column: string, value: mixed} $where + * @param array{caseSensitive: bool, column: string, value: mixed} $where */ public function whereLike(Builder $query, $where): string { - return match ((bool) $where['caseInsensitive']) { - true => "{$this->wrap($where['column'])} ilike {$this->parameter($where['value'])}", - false => "{$this->wrap($where['column'])} like {$this->parameter($where['value'])}", - }; + $where['operator'] = $where['not'] ? 'not ' : ''; + $where['operator'] .= $where['caseSensitive'] ? 'like' : 'ilike'; + + return "{$this->wrap($where['column'])} {$where['operator']} {$this->parameter($where['value'])}"; } /** From 96325a82c146f25df034108ff37821f783b56569 Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Wed, 24 Jul 2024 15:59:16 +0200 Subject: [PATCH 3/7] docs: update case sensitivity --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 649eb33..075a306 100644 --- a/README.md +++ b/README.md @@ -195,7 +195,7 @@ Schema::createFunction( A sixth parameter lets you define further options for the function. Please [read the manual](https://www.postgresql.org/docs/current/sql-createfunction.html) for the exact meaning, some of them set enable or disable ways for PostgreSQL to optimize the execution. | Option | Values | Description | -|----------------|-----------------------------------|----------------------------------------------------------------------------------------------------------------| +| -------------- | --------------------------------- | -------------------------------------------------------------------------------------------------------------- | | `calledOnNull` | bool | Defines whether the function should be called for NULL values. | | `cost` | integer | Defines the cost for executing the function. | | `leakproof` | bool | Informs whether the function has side effects. | @@ -254,7 +254,7 @@ Schema::table('projects', function (Blueprint $table): void { The following table contains all of the available trigger modifiers: | Modifier | Description | -|-----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `->forEachRow()` | The trigger will be called for every row. | | `->forEachStatement()` | The trigger will be called once for each statement *(default)*. | | `->transitionTables(`
` old: 'oldrows',`
` new: 'newrows',`
`)` | The forEachStatement-trigger will provide the before/after state of the affected rows in special tables. You can omit either option if not valid for this trigger. | @@ -1018,7 +1018,7 @@ User::query() In addition to the basic form of a Common Table Expression these optional settings are available to support all PostgreSQL options: | Option | Type | Description | -|--------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| ------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | materialized | `bool` | Whether the CTE should be (not) materialized. This overrides PostgreSQL's automatic materialization decision. [(Documentation)](https://www.postgresql.org/docs/current/queries-with.html#id-1.5.6.12.7) | | recursive | `bool` | Whether to use a recursive CTE. [(Documentation)](https://www.postgresql.org/docs/current/queries-with.html#QUERIES-WITH-RECURSIVE) | | cycle | `string` | Specify the automatic cycle detection settings for recursive queries. [(Documentation)](https://www.postgresql.org/docs/current/queries-with.html#QUERIES-WITH-CYCLE) | @@ -1103,11 +1103,11 @@ $query->orWhereNotBoolean($column, bool $value); #### Like -With the `whereLike` scope you can compare a column to a (case-insensitive) value. +With the `whereLike` scope you can compare a column to a (case-sensitive) value. ```php -$query->whereLike($column, $value, $caseInsensitive = false); -$query->orWhereLike($column, $value, $caseInsensitive = false); +$query->whereLike($column, $value, $caseSensitive = false); +$query->orWhereLike($column, $value, $caseSensitive = false); ``` #### Between Symmetric @@ -1170,7 +1170,7 @@ Some of the PostgreSQL types are represented in a string format that a Laravel a To make those types usable, these casts can be used with your eloquent models: | Type | Cast | -|----------------|-------------------------------------------------------------| +| -------------- | ----------------------------------------------------------- | | `integerArray` | `Tpetry\PostgresqlEnhanced\Eloquent\Casts\IntegerArrayCast` | | `vector` | `Tpetry\PostgresqlEnhanced\Eloquent\Casts\VectorArray` | From fda6d6ff1fd621d2afd43d78ef42fd1da2dac127 Mon Sep 17 00:00:00 2001 From: tpetry Date: Wed, 31 Jul 2024 11:09:05 +0200 Subject: [PATCH 4/7] improvements --- src/Query/BuilderWhere.php | 3 +++ src/Query/GrammarWhere.php | 8 ++++---- src/Schema/Grammars/GrammarTable.php | 2 +- tests/Query/WhereTest.php | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Query/BuilderWhere.php b/src/Query/BuilderWhere.php index 18eaece..5fd3684 100644 --- a/src/Query/BuilderWhere.php +++ b/src/Query/BuilderWhere.php @@ -63,6 +63,7 @@ public function orWhereIntegerArrayMatches($column, string $query): static * * @param Expression|string $column * @param Expression|string $value + * @param bool $caseSensitive */ public function orWhereLike($column, $value, $caseSensitive = false): static { @@ -181,7 +182,9 @@ public function whereIntegerArrayMatches($column, string $query): static * * @param Expression|string $column * @param Expression|string $value + * @param bool $caseSensitive * @param string $boolean + * @param bool $not */ public function whereLike($column, $value, $caseSensitive = false, $boolean = 'and', $not = false): static { diff --git a/src/Query/GrammarWhere.php b/src/Query/GrammarWhere.php index 186f1be..0c792b9 100644 --- a/src/Query/GrammarWhere.php +++ b/src/Query/GrammarWhere.php @@ -50,10 +50,10 @@ public function whereAny(Builder $query, $where): string */ public function whereLike(Builder $query, $where): string { - $where['operator'] = $where['not'] ? 'not ' : ''; - $where['operator'] .= $where['caseSensitive'] ? 'like' : 'ilike'; - - return "{$this->wrap($where['column'])} {$where['operator']} {$this->parameter($where['value'])}"; + return match ($where['caseSensitive']) { + true => "{$this->wrap($where['column'])} like {$this->parameter($where['value'])}", + false => "{$this->wrap($where['column'])} ilike {$this->parameter($where['value'])}", + }; } /** diff --git a/src/Schema/Grammars/GrammarTable.php b/src/Schema/Grammars/GrammarTable.php index dc48f55..a10ea46 100644 --- a/src/Schema/Grammars/GrammarTable.php +++ b/src/Schema/Grammars/GrammarTable.php @@ -4,8 +4,8 @@ namespace Tpetry\PostgresqlEnhanced\Schema\Grammars; +use Arr; use Illuminate\Database\Schema\Blueprint; -use Illuminate\Support\Arr; use Illuminate\Support\Fluent; trait GrammarTable diff --git a/tests/Query/WhereTest.php b/tests/Query/WhereTest.php index 097bd90..7c7de50 100644 --- a/tests/Query/WhereTest.php +++ b/tests/Query/WhereTest.php @@ -99,7 +99,7 @@ public function testOrWhereLike(): void $this->getConnection()->table('example')->orWhereLike('str', 'OamekKIC', true)->orWhereLike('str', 'HmC3xURl', true)->get(); }); $this->assertEquals( - ['select * from "example" where "str" like ? or "str" like ?', 'select * from "example" where "str" ilike ? or "str" ilike ?'], + ['select * from "example" where "str" ilike ? or "str" ilike ?', 'select * from "example" where "str" like ? or "str" like ?'], array_column($queries, 'query'), ); $this->assertEquals( @@ -258,7 +258,7 @@ public function testWhereLike(): void $this->getConnection()->table('example')->whereLike('str', 'IcuC5Cqz', true)->get(); }); $this->assertEquals( - ['select * from "example" where "str" like ?', 'select * from "example" where "str" ilike ?'], + ['select * from "example" where "str" ilike ?', 'select * from "example" where "str" like ?'], array_column($queries, 'query'), ); $this->assertEquals( From 810d55325654cbf91aa9668423e4109c18446db9 Mon Sep 17 00:00:00 2001 From: tpetry Date: Wed, 31 Jul 2024 11:11:40 +0200 Subject: [PATCH 5/7] undo markdown-changes --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 075a306..2823c57 100644 --- a/README.md +++ b/README.md @@ -195,7 +195,7 @@ Schema::createFunction( A sixth parameter lets you define further options for the function. Please [read the manual](https://www.postgresql.org/docs/current/sql-createfunction.html) for the exact meaning, some of them set enable or disable ways for PostgreSQL to optimize the execution. | Option | Values | Description | -| -------------- | --------------------------------- | -------------------------------------------------------------------------------------------------------------- | +|----------------|-----------------------------------|----------------------------------------------------------------------------------------------------------------| | `calledOnNull` | bool | Defines whether the function should be called for NULL values. | | `cost` | integer | Defines the cost for executing the function. | | `leakproof` | bool | Informs whether the function has side effects. | @@ -254,7 +254,7 @@ Schema::table('projects', function (Blueprint $table): void { The following table contains all of the available trigger modifiers: | Modifier | Description | -| --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +|-----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `->forEachRow()` | The trigger will be called for every row. | | `->forEachStatement()` | The trigger will be called once for each statement *(default)*. | | `->transitionTables(`
` old: 'oldrows',`
` new: 'newrows',`
`)` | The forEachStatement-trigger will provide the before/after state of the affected rows in special tables. You can omit either option if not valid for this trigger. | @@ -1018,7 +1018,7 @@ User::query() In addition to the basic form of a Common Table Expression these optional settings are available to support all PostgreSQL options: | Option | Type | Description | -| ------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +|--------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | materialized | `bool` | Whether the CTE should be (not) materialized. This overrides PostgreSQL's automatic materialization decision. [(Documentation)](https://www.postgresql.org/docs/current/queries-with.html#id-1.5.6.12.7) | | recursive | `bool` | Whether to use a recursive CTE. [(Documentation)](https://www.postgresql.org/docs/current/queries-with.html#QUERIES-WITH-RECURSIVE) | | cycle | `string` | Specify the automatic cycle detection settings for recursive queries. [(Documentation)](https://www.postgresql.org/docs/current/queries-with.html#QUERIES-WITH-CYCLE) | From 566dd514cd04e4c873f4ffb445d4c9f88dea7871 Mon Sep 17 00:00:00 2001 From: tpetry Date: Wed, 31 Jul 2024 11:12:10 +0200 Subject: [PATCH 6/7] undo markdown-changes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2823c57..4e49458 100644 --- a/README.md +++ b/README.md @@ -1170,7 +1170,7 @@ Some of the PostgreSQL types are represented in a string format that a Laravel a To make those types usable, these casts can be used with your eloquent models: | Type | Cast | -| -------------- | ----------------------------------------------------------- | +|----------------|-------------------------------------------------------------| | `integerArray` | `Tpetry\PostgresqlEnhanced\Eloquent\Casts\IntegerArrayCast` | | `vector` | `Tpetry\PostgresqlEnhanced\Eloquent\Casts\VectorArray` | From 2ed34ed0173ef43e28b5f5fa8d0622e0f0f09774 Mon Sep 17 00:00:00 2001 From: tpetry Date: Wed, 31 Jul 2024 11:13:57 +0200 Subject: [PATCH 7/7] changed whereLike description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e49458..a4adf19 100644 --- a/README.md +++ b/README.md @@ -1103,7 +1103,7 @@ $query->orWhereNotBoolean($column, bool $value); #### Like -With the `whereLike` scope you can compare a column to a (case-sensitive) value. +With the `whereLike` scope you can do case-(in)sensitive like comparisons between a column and a value. ```php $query->whereLike($column, $value, $caseSensitive = false);