mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Enhance search column expression for pgsql prefix (#19694)
* Enhance search column expression for pgsql prefix Added support for Laravel table prefix in PostgreSQL. Signed-off-by: Max <mstaack@users.noreply.github.com> * Update helpers.php * Update helpersTest.php --------- Signed-off-by: Max <mstaack@users.noreply.github.com> Co-authored-by: Dan Harrin <git@danharrin.com>
This commit is contained in:
@@ -245,6 +245,10 @@ if (! function_exists('Filament\Support\generate_search_column_expression')) {
|
||||
{
|
||||
$driverName = $databaseConnection->getDriverName();
|
||||
|
||||
if ($driverName === 'pgsql' && str_contains($column, '.')) {
|
||||
$column = $databaseConnection->getTablePrefix() . $column;
|
||||
}
|
||||
|
||||
$column = match ($driverName) {
|
||||
'pgsql' => (
|
||||
str($column)->contains('->')
|
||||
|
||||
@@ -111,6 +111,7 @@ it('will generate a column expression for Postgres with colons in the table name
|
||||
|
||||
$databaseConnection = Mockery::mock(Connection::class);
|
||||
$databaseConnection->shouldReceive('getDriverName')->andReturn('pgsql');
|
||||
$databaseConnection->shouldReceive('getTablePrefix')->andReturn('');
|
||||
$databaseConnection->shouldReceive('getConfig')->with('search_collation')->andReturn(null);
|
||||
|
||||
$grammar = new PostgresGrammar($databaseConnection);
|
||||
@@ -125,6 +126,26 @@ it('will generate a column expression for Postgres with colons in the table name
|
||||
['blog:posts:comments.author.name', 'lower("blog:posts:comments"."author"."name"::text)'],
|
||||
]);
|
||||
|
||||
it('will generate a search column expression for Postgres with a table prefix', function (string $column, string $expectedExpression): void {
|
||||
$isSearchForcedCaseInsensitive = true;
|
||||
|
||||
$databaseConnection = Mockery::mock(Connection::class);
|
||||
$databaseConnection->shouldReceive('getDriverName')->andReturn('pgsql');
|
||||
$databaseConnection->shouldReceive('getTablePrefix')->andReturn('app_');
|
||||
$databaseConnection->shouldReceive('getConfig')->with('search_collation')->andReturn(null);
|
||||
|
||||
$grammar = new PostgresGrammar($databaseConnection);
|
||||
|
||||
$actualExpression = generate_search_column_expression($column, $isSearchForcedCaseInsensitive, $databaseConnection);
|
||||
|
||||
expect($actualExpression->getValue($grammar))
|
||||
->toBe($expectedExpression);
|
||||
})
|
||||
->with([
|
||||
['posts.title', 'lower("app_posts"."title"::text)'],
|
||||
['posts.data->name', "lower(\"app_posts\".\"data\"->>'name'::text)"],
|
||||
]);
|
||||
|
||||
it('will generate a JSON search column expression for Postgres with explicit ->> operator', function (): void {
|
||||
$column = 'data->>name';
|
||||
$isSearchForcedCaseInsensitive = true;
|
||||
|
||||
Reference in New Issue
Block a user