Skip to content
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

Add Support for PostgreSQL jsonb_insert Function #107

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions src/Query/AST/Functions/Postgresql/JsonbInsert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Scienta\DoctrineJsonFunctions\Query\AST\Functions\Postgresql;

/**
* "JSONB_INSERT" "(" StringPrimary "," StringPrimary "," StringPrimary ")".
*/
class JsonbInsert extends PostgresqlJsonFunctionNode
{
public const FUNCTION_NAME = 'JSONB_INSERT';

/** @var string[] */
protected $requiredArgumentTypes = [self::STRING_PRIMARY_ARG, self::STRING_PRIMARY_ARG, self::STRING_PRIMARY_ARG];

/** @var string[] */
protected $optionalArgumentTypes = [self::STRING_PRIMARY_ARG];
}
18 changes: 18 additions & 0 deletions tests/Query/Functions/Postgresql/JsonbInsertTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Scienta\DoctrineJsonFunctions\Tests\Query\Functions\Postgresql;

use Scienta\DoctrineJsonFunctions\Tests\Query\PostgresqlTestCase;

class JsonbInsertTest extends PostgresqlTestCase
{
public function testSelect()
{
$this->assertDqlProducesSql(
"SELECT JSONB_INSERT(d.jsonCol,'{0}',d.jsonData) FROM Scienta\DoctrineJsonFunctions\Tests\Entities\JsonData d",
"SELECT jsonb_insert(j0_.jsonCol, '{0}', j0_.jsonData) AS sclr_0 FROM JsonData j0_"
);
}
}
1 change: 1 addition & 0 deletions tests/Query/PostgresqlTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function setUp(): void
public static function loadDqlFunctions(Configuration $configuration)
{
$configuration->addCustomStringFunction(DqlFunctions\JsonbContains::FUNCTION_NAME, DqlFunctions\JsonbContains::class);
$configuration->addCustomStringFunction(DqlFunctions\JsonbInsert::FUNCTION_NAME, DqlFunctions\JsonbInsert::class);
$configuration->addCustomStringFunction(DqlFunctions\JsonGetText::FUNCTION_NAME, DqlFunctions\JsonGetText::class);
}
}
Loading