All Projects → goodwix → doctrine-json-odm

goodwix / doctrine-json-odm

Licence: MIT License
JSON Object-Document Mapping bundle for Symfony and Doctrine

Programming Languages

PHP
23972 projects - #3 most used programming language
Dockerfile
14818 projects
shell
77523 projects

Projects that are alternatives of or similar to doctrine-json-odm

Sonatadoctrineormadminbundle
Integrate Doctrine ORM into the SonataAdminBundle
Stars: ✭ 400 (+2566.67%)
Mutual labels:  orm, symfony-bundle, doctrine
Doctrine Json Odm
An object document mapper for Doctrine ORM using JSON types of modern RDBMS.
Stars: ✭ 420 (+2700%)
Mutual labels:  symfony-bundle, doctrine, odm
EasyAuditBundle
A Symfony Bundle To Log Selective Events
Stars: ✭ 84 (+460%)
Mutual labels:  symfony-bundle, symfony4
Express Cassandra
Cassandra ORM/ODM/OGM for Node.js with optional support for Elassandra & JanusGraph
Stars: ✭ 163 (+986.67%)
Mutual labels:  orm, odm
Auditor Bundle
Doctrine audits logs made easy.
Stars: ✭ 221 (+1373.33%)
Mutual labels:  orm, symfony-bundle
Framework
Strongly-typed JavaScript object with support for validation and error handling.
Stars: ✭ 136 (+806.67%)
Mutual labels:  orm, odm
Awesome Doctrine
A collection of useful Doctrine snippets.
Stars: ✭ 147 (+880%)
Mutual labels:  orm, doctrine
Qxorm
QxOrm library - C++ Qt ORM (Object Relational Mapping) and ODM (Object Document Mapper) library - Official repository
Stars: ✭ 176 (+1073.33%)
Mutual labels:  orm, odm
Dtcqueuebundle
Symfony2/3/4/5 Queue Bundle (for background jobs) supporting Mongo (Doctrine ODM), Mysql (and any Doctrine ORM), RabbitMQ, Beanstalkd, Redis, and ... {write your own}
Stars: ✭ 115 (+666.67%)
Mutual labels:  orm, doctrine
EasyAdminPlusBundle
EasyAdminPlusBundle is a Symfony 4 wrapper for the amazing EasyCorp/EasyAdminBundle
Stars: ✭ 39 (+160%)
Mutual labels:  symfony-bundle, symfony4
sonata-multiupload-bundle
No description or website provided.
Stars: ✭ 29 (+93.33%)
Mutual labels:  symfony-bundle, symfony4
symbok-bundle
Symfony annotations bundle
Stars: ✭ 50 (+233.33%)
Mutual labels:  symfony-bundle, doctrine
Dynamo Easy
DynamoDB client for NodeJS and browser with a fluent api to build requests. We take care of the type mapping between JS and DynamoDB, customizable trough typescript decorators.
Stars: ✭ 133 (+786.67%)
Mutual labels:  orm, odm
Js Data
Give your data the treatment it deserves with a framework-agnostic, datastore-agnostic JavaScript ORM built for ease of use and peace of mind. Works in Node.js and in the Browser. Main Site: http://js-data.io, API Reference Docs: http://api.js-data.io/js-data
Stars: ✭ 1,599 (+10560%)
Mutual labels:  orm, odm
Orm Pack
A Symfony Pack for Doctrine ORM
Stars: ✭ 1,850 (+12233.33%)
Mutual labels:  orm, doctrine
Awesome Python Models
A curated list of awesome Python libraries, which implement models, schemas, serializers/deserializers, ODM's/ORM's, Active Records or similar patterns.
Stars: ✭ 124 (+726.67%)
Mutual labels:  orm, odm
Wither
An ODM for MongoDB built on the official MongoDB Rust driver.
Stars: ✭ 174 (+1060%)
Mutual labels:  orm, odm
DoctrineMongoODMModule
Laminas Module for Doctrine MongoDB ODM
Stars: ✭ 83 (+453.33%)
Mutual labels:  doctrine, odm
Factory Bot
🤖 Provides a fixture factory for doctrine/orm entities.
Stars: ✭ 57 (+280%)
Mutual labels:  orm, doctrine
Orango
ArangoDB Object Modeling for Node.js, Foxx and Modern Web Browsers
Stars: ✭ 103 (+586.67%)
Mutual labels:  orm, odm

Doctrine JSON ODM library

Latest Stable Version Total Downloads License Build Status Code Coverage Scrutinizer Code Quality

Inspired by https://github.com/dunglas/doctrine-json-odm

This is beta version of library. Main differences from Dunglas library:

  • library does not store any metadata in json field;
  • doctrine ODM type uses main Symfony serializer service (so you can easily extend serialization process by adding normalizers/denormalizers globally in dependency injection config);
  • automatic registration of ODM types for Doctrine (using Symfony autowiring and autoconfigure features).

Features

  • Object-Document Mapping with database json types
  • Doctrine 2.5+ support
  • PostgreSQL 9.4+ support
  • Symfony 5+ support (not tested with previous versions)
  • MySQL support not tested

Additional features

  • Automatic registering normalizers for use with Java-like collections from ramsey/collection library

Install

Install with Symfony 4

To install the library, use Composer.

composer require goodwix/doctrine-json-odm

Add lines to config/bundles.php (no automatic configuration is available for beta version).

<?php

return [
    // ...
    Goodwix\DoctrineJsonOdm\Bridge\Symfony\DoctrineJsonOdmBundle::class => ['all' => true],
];

Create package config file config/packages/doctrine-json-odm.yaml with next content.

doctrine_json_odm:
  mapping:
    paths:
      - '%kernel.project_dir%/src/ODM'

there src/ODM is the root path for your ODM entities (like src/Entity for Doctrine).

Usage

Basic usage with automatic ODM types registration

Create entity class for ODM type in ODM-specific directory (like src/ODM) and mark it with \Goodwix\DoctrineJsonOdm\Annotation\ODM annotation.

namespace App\ODM;

use Goodwix\DoctrineJsonOdm\Annotation\ODM;

/**
 * @ODM()
 */
class Document
{
    /** @var string */
    public $title;

    /** @var string */
    public $description;
}

Create doctrine entity class with field type App\ODM\Document.

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use App\ODM\Document;

/**
 * @ORM\Entity()
 */
class DocumentStorage
{
    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     * @var int
     */
    public $id;

    /**
     * @ORM\Column(type=Document::class, nullable=true)
     *
     * @var Document
     */
    public $document;
}

Now you can easily manage your ORM entity with ODM class field

$documentStorage = $entityManager->find(DocumentStorage::class, $id);
$documentStorage->document->title = 'ODM document title';
$documentStorage->document->description = 'ODM document description';

Manual usage with Doctrine and Symfony Serializer component

To manually register Doctrine ODM types use ODMType::registerODMType() method.

require_once __DIR__.'/../vendor/autoload.php';

use Goodwix\DoctrineJsonOdm\Type\ODMType;
use Symfony\Component\Serializer\SerializerInterface;

class Document { }

ODMType::registerODMType(
    Document::class,
    new class implements SerializerInterface
    {
        public function serialize($data, $format, array $context = [])  { /* Implement serialize() method. */ }
        public function deserialize($data, $type, $format, array $context = [])  { /* Implement deserialize() method. */ }
    }
);

Examples with Symfony application

You can see example of Symfony 4 application with using ODM library in this directory.

Deal with abstract

As an abstract class could not be created as an instance, each concrete children have to be mapped into the abstract class.

Indeed, the Symfony Serializer must know the real type in this case through a discriminator field to determine the real object behind the stored data. For that, it use Symfony\Component\Serializer\Annotation\DiscriminatorMap. More info is available [here]( Maybe this way : Symfony serializer : discriminator

For example, if we have an abstract and 2 children

<?php

declare(strict_types=1);

namespace App\Whatever;

use Symfony\Component\Serializer\Annotation\DiscriminatorMap;

#### PHP8 Attribute ####
#[DiscriminatorMap(
    typeProperty: 'type',
    mapping: [
        'myChildTypeName' => 'App\Whatever\Child',
        'myChild2TypeName' => 'App\Whatever\Child2',
    ]
)]
####> PHP8 Attribute ####


#### PHP < PHP8 ####
/**
 * @DiscriminatorMap(typeProperty="type", mapping={
 *    "myChildTypeName"="App\Whatever\Child",
 *    "myChild2TypeName"="App\Whatever\Child2"
 * })
 */
####> PHP < PHP8 ####


abstract class MyAbstract
{
}

class Child extends MyAbstract
{}


class Child2 extends MyAbstract
{}

Contribution

You can run composer lint before pushing to repository to ensure that there are no code style errors.

Please remember to add some tests if you change library code.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].