Download the PHP package boldtrn/jsonb-bundle without Composer
On this page you can find all versions of the php package boldtrn/jsonb-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download boldtrn/jsonb-bundle
More information about boldtrn/jsonb-bundle
Files in boldtrn/jsonb-bundle
Package jsonb-bundle
Short Description A library adding the support for JSONB columns of PostgreSQL to Doctrine.
License MIT
Homepage https://github.com/boldtrn/JsonbBundle
Informations about the package jsonb-bundle
JsonbBundle
Doctrine implemented the jsonb
datatype with Doctrine DBAL 2.6. I recommend using the official Doctrine implementation. If you cannot upgrade feel free to use this bundle. It still works for me in my current production setting. I will upgrade to the doctrine implementation at some point in time, as well.
Doctrine Mapping Matrix
This bundle extends Doctrine to use the jsonb
datatype that ships with Postgresql 9.4.
This bundle is fully compatible with Symfony, but you do not have to use Symfony (see the composer.json
for dependencies).
Please make sure you have Postgresql with a version of at least 9.4 installed before using this bundle.
The Bundle allows to create Jsonb fields and use the @>
,?
and the #>>
operator on the Jsonb field.
Other Operations can be easily added.
I recently discovered the power of NativeQueries (http://doctrine-orm.readthedocs.org/en/latest/reference/native-sql.html). Right now I only use NativeQueries when querying. An example is shown below.
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
Step 2: Add the new Types and Functions to the Config
Note: There were people having issues with the above configuration. They had the following exception:
This was fixed by changing the dql part in the following (add the entity_managers
between orm
and dql
):
Step 3: Create a Entity and Use the Jsonb Type
Step 4.1: Write a Repository Method using a NativeQuery
You only need to setup the $rsm
ResultSetMapping according to the Doctrine documentation.
Step 4.2: Write a Repository Method that queries for the jsonb using the custom JSONB_FUNCTIONS
This example shows how to use the contains statement in a WHERE clause.
The = TRUE
is a workaround for Doctrine that needs an comparison operator in the WHERE clause.
This produces the following Query:
This example shows how to query for a value that is LIKE %d%
The result could be data like:
This produces the following Query:
Further Information
The ?
operator is implemented by calling its function jsonb_exists(column_name, value)
since Doctrine will consider it a parameter placeholder otherwise. The same must be done if you want to implement ?|
and ?&
operators, using jsonb_exists_any(column_name, value)
and jsonb_exists_all(column_name, value)
respectively