You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(type): add jsonb_document type for DBAL 4.3.0+
New jsonb_document type leveraging native DBAL JsonbType.
Shared serialization logic extracted into JsonDocumentTypeTrait.
Type is conditionally registered when DBAL 4.3.0+ is available.
Copy file name to clipboardExpand all lines: README.md
+24-4Lines changed: 24 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,10 +33,12 @@ If you use Doctrine directly, use a bootstrap code similar to the following:
33
33
34
34
require_once __DIR__.'/../vendor/autoload.php'; // Adjust to your path
35
35
36
+
use Doctrine\DBAL\Types\JsonbType;
36
37
use Doctrine\DBAL\Types\Type;
37
38
use Doctrine\ORM\EntityManager;
38
39
use Doctrine\ORM\Tools\Setup;
39
40
use Dunglas\DoctrineJsonOdm\Serializer;
41
+
use Dunglas\DoctrineJsonOdm\Type\JsonbDocumentType;
40
42
use Dunglas\DoctrineJsonOdm\Type\JsonDocumentType;
41
43
use Symfony\Component\Serializer\Encoder\JsonEncoder;
42
44
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
@@ -45,11 +47,17 @@ use Symfony\Component\Serializer\Normalizer\UidNormalizer;
45
47
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
46
48
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
47
49
50
+
$serializer = new Serializer([new BackedEnumNormalizer(), new UidNormalizer(), new DateTimeNormalizer(), new ArrayDenormalizer(), new ObjectNormalizer()], [new JsonEncoder()]);
new Serializer([new BackedEnumNormalizer(), new UidNormalizer(), new DateTimeNormalizer(), new ArrayDenormalizer(), new ObjectNormalizer()], [new JsonEncoder()])
Doctrine JSON ODM provides a `json_document` column type for properties of Doctrine entities.
81
+
Starting with Doctrine DBAL 4.3.0+, a `jsonb_document` type is also available, leveraging native JSONB support.
73
82
74
83
The content of properties mapped with this type is serialized in JSON using the [Symfony Serializer](http://symfony.com/doc/current/components/serializer.html)
75
84
then, it is stored in a dynamic JSON column in the database.
@@ -236,7 +245,18 @@ Doctrine ORM 2.6+ and DBAL 2.6+ are supported.
236
245
237
246
**How to use [the JSONB type of PostgreSQL](http://www.postgresql.org/docs/current/static/datatype-json.html)?**
238
247
239
-
Then, you need to set an option in the column mapping:
248
+
With Doctrine DBAL 4.3.0+, use the dedicated `jsonb_document` type:
249
+
250
+
```php
251
+
// ...
252
+
253
+
#[Column(type: 'jsonb_document')]
254
+
public $foo;
255
+
256
+
// ...
257
+
```
258
+
259
+
For older DBAL versions, set an option in the column mapping:
0 commit comments