{"id":20887622,"url":"https://github.com/opsway/doctrine-dbal-postgresql","last_synced_at":"2025-05-15T03:06:56.231Z","repository":{"id":29876022,"uuid":"33421292","full_name":"opsway/doctrine-dbal-postgresql","owner":"opsway","description":"Add JSON query support to Doctrine DBAL and DQL","archived":false,"fork":false,"pushed_at":"2025-01-10T10:23:19.000Z","size":122,"stargazers_count":162,"open_issues_count":9,"forks_count":38,"subscribers_count":48,"default_branch":"master","last_synced_at":"2025-04-14T03:08:25.338Z","etag":null,"topics":["dbal","doctrine","opsway-opensource","php","postgresql"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opsway.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-04-04T21:39:09.000Z","updated_at":"2025-02-02T09:43:00.000Z","dependencies_parsed_at":"2024-02-20T13:28:08.159Z","dependency_job_id":"0c182887-e3c5-4566-b6ba-752e824cfb03","html_url":"https://github.com/opsway/doctrine-dbal-postgresql","commit_stats":{"total_commits":61,"total_committers":21,"mean_commits":"2.9047619047619047","dds":0.8524590163934427,"last_synced_commit":"08d000242a11e450e1be601029728f0ec5ac6be9"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opsway%2Fdoctrine-dbal-postgresql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opsway%2Fdoctrine-dbal-postgresql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opsway%2Fdoctrine-dbal-postgresql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opsway%2Fdoctrine-dbal-postgresql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opsway","download_url":"https://codeload.github.com/opsway/doctrine-dbal-postgresql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254264766,"owners_count":22041793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dbal","doctrine","opsway-opensource","php","postgresql"],"created_at":"2024-11-18T08:21:22.593Z","updated_at":"2025-05-15T03:06:51.219Z","avatar_url":"https://github.com/opsway.png","language":"PHP","funding_links":[],"categories":["Related Projects"],"sub_categories":[],"readme":"doctrine-dbal-postgresql\n=========================\n[![Latest Stable Version](https://poser.pugx.org/opsway/doctrine-dbal-postgresql/v/stable)](https://packagist.org/packages/opsway/doctrine-dbal-postgresql) [![Total Downloads](https://poser.pugx.org/opsway/doctrine-dbal-postgresql/downloads)](https://packagist.org/packages/opsway/doctrine-dbal-postgresql) [![Latest Unstable Version](https://poser.pugx.org/opsway/doctrine-dbal-postgresql/v/unstable)](https://packagist.org/packages/opsway/doctrine-dbal-postgresql) \n\nThis component allows you to manage some native [PostgreSQL](http://www.postgresql.org)\ndata types, operators and functions with the Doctrine [DBAL](http://www.doctrine-project.org/projects/dbal.html) component.\n\nUsage\n-----\n\nAdd to composer.json\n```bash\nphp composer.phar require opsway/doctrine-dbal-postgresql ~0.8\n```\nTo use the new types you should register them using the [Custom Mapping Types](https://doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#custom-mapping-types) feature.\n\nTo use the new functions you should register them using the [DQL User Defined Functions](https://www.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/dql-user-defined-functions.html) feature.\n\n#### Custom Types\n\n* Array Integer (integer[])\n* Array BigInt (bigint[])\n* TsVector (tsvector)\n\n\n\n#### Custom DQL functions\n\n* CONTAINS -              'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\Contains'\n* CONTAINED -             'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\Contained'\n* GET_JSON_FIELD -        'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\GetJsonField'\n* GET_JSON_FIELD_BY_KEY - 'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\GetJsonFieldByKey'\n* GET_JSON_OBJECT -       'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\GetJsonObject'\n* GET_JSON_OBJECT_TEXT -  'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\GetJsonObjectText'\n* ANY_OP -                'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\Any'\n* ALL_OP -                'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\All'\n* ARR -                   'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\Arr'\n* ARR_AGGREGATE -         'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\ArrayAggregate'\n* ARR_APPEND -            'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\ArrayAppend'\n* ARR_REPLACE -           'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\ArrayReplace'\n* REGEXP_REPLACE -        'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\RegexpReplace'\n* ARR_REMOVE -            'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\ArrayRemove'\n* ARR_CONTAINS -          'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\ArrayContains'\n* TO_TSQUERY -            'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\ToTsquery'\n* TO_TSVECTOR -           'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\ToTsvector'\n* TS_CONCAT_OP -          'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\TsConcat'\n* TS_MATCH_OP -           'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\TsMatch'\n* UNNEST -                'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\Unnest'\n* JSON_AGG -              'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\JsonAgg'\n* JSONB_ARRAY_ELEM_TEXT - 'OpsWay\\Doctrine\\ORM\\Query\\AST\\Functions\\JsonbArrayElementsText'\n\n### Custom DQL function usage\nFor an example the CONTAINS function requires your table column in your database to be of the type ```jsonb```.\nOtherwise PostgreSQL will not recognize the operator needed to perform this action. (@\u003e) \n* Tip: Based on the function you want to use, check if there are any specific column type requirements. \n\nExample query:\n```php\n$result = $this-\u003eem-\u003ecreateQuery(\n    'SELECT l FROM Foo\\Bar\\Baz l WHERE CONTAINS(l.metaData, :value) = true')\n    -\u003esetParameter('value', json_encode(['foo'=\u003e'bar']))\n    -\u003egetResult();\n```\nSetting the column type to ```jsonb```. \n```\n/**\n * @var array\n *\n * @ORM\\Column(type=\"json\", nullable=true, options={\"jsonb\": true})\n */\nprivate $metaData;\n```\n\n**Note:** If you want to use these DQL functions on an existing `json` field, you will have to alter its column type (running `make:migration` after adding `options={\"jsonb\": true}` will not be enough). This migration is an example of how you can do it:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace DoctrineMigrations;\n\nuse Doctrine\\DBAL\\Schema\\Schema;\nuse Doctrine\\Migrations\\AbstractMigration;\n\nfinal class VersionXXX extends AbstractMigration\n{\n    public function up(Schema $schema): void\n    {\n        $this-\u003eaddSql('ALTER TABLE \"user\" ALTER COLUMN roles SET DATA TYPE jsonb');\n    }\n\n    public function down(Schema $schema): void\n    {\n        $this-\u003eaddSql('ALTER TABLE \"user\" ALTER COLUMN roles SET DATA TYPE json');\n    }\n}\n```\n\n| Custom Name           | PostgreSql                | Usage in DQL                               | Result in SQL                    |\n|-----------------------|:-------------------------:|--------------------------------------------|----------------------------------|\n| CONTAINS              |            @\u003e             | CONTAINS(field, :param)                    | (field @\u003e '{value}')             |\n| CONTAINED             |            \u003c@             | CONTAINED(field, :param)                   | (field \u003c@ '{value}')             |\n| GET_JSON_FIELD        |            -\u003e\u003e            | GET_JSON_FIELD(field, 'json_field')        | (table_field-\u003e\u003e'json_field')     |\n| GET_JSON_FIELD_BY_KEY |            -\u003e             | GET_JSON_FIELD_BY_KEY(field, 'json_field') | (table_field-\u003e'json_field')      |\n| GET_JSON_OBJECT       |            #\u003e             | GET_JSON_OBJECT(field, 'json_field')       | (table_field#\u003e'json_field')      |\n| GET_JSON_OBJECT_TEXT  |            #\u003e\u003e            | GET_JSON_OBJECT_TEXT(field, 'json_field')  | (table_field#\u003e\u003e'json_field')     |\n| ANY_OP                |            ANY            | ANY_OP(field)                              | ANY(field)                       |\n| ALL_OP                |            ALL            | ALL_OP(field)                              | ALL(field)                       |\n| ARR                   |           ARRAY           | ARR(field)                                 | ARRAY[field]                     |\n| ARR_AGGREGATE         |        array_agg          | ARR_AGGREGATE(field)                       | array_agg(field)                 |\n| ARR_APPEND            |       array_append        | ARR_APPEND(field, :param)                  | array_append(field, param)       |\n| ARR_REPLACE           |       array_replace       | ARR_REPLACE(field, :param1, :param2)       | array_replace(field, p1, p2)     |\n| REGEXP_REPLACE        |       regexp_replace      | REGEXP_REPLACE(field, :param1, :param2)    | regexp_replace(field, p1, p2)    |\n| ARR_REMOVE            |       array_remove        | ARR_REMOVE(field, :param)                  | array_remove(field, param)       |\n| ARR_CONTAINS          |            \u0026\u0026             | ARR_CONTAINS(field, :param)                | (field \u0026\u0026 param)                 |\n| TO_TSQUERY            |        to_tsquery         | TO_TSQUERY(:param)                         | to_tsquery('param')              |\n| TO_TSVECTOR           |        to_tsvector        | TO_TSVECTOR(field)                         | to_tsvector(field)               |\n| TS_MATCH_OP           |            @@             | TS_MATCH_OP(expr1, expr2)                  | expr1 @@ expr2                   |\n| TS_CONCAT_OP          |            ||             | TS_CONCAT_OP(expr1, expr2, ....)           | (expr1 || expr2 || ...)          |\n| UNNEST                |          UNNEST           | UNNEST(field)                              | UNNEST(field)                    |\n| JSON_AGG              |         json_agg          | JSON_AGG(expression)                       | json_agg(expression)             |\n| JSONB_ARRAY_ELEM_TEXT | jsonb_array_elements_text | JSONB_ARRAY_ELEM_TEXT(field, 'json_field') | jsonb_array_elements_text(field) |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopsway%2Fdoctrine-dbal-postgresql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopsway%2Fdoctrine-dbal-postgresql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopsway%2Fdoctrine-dbal-postgresql/lists"}