syndesi/cypher-entity-manager

Provides an entity manager for Cypher data types

0.1.0 2023-12-03 10:40 UTC

This package is auto-updated.

Last update: 2024-05-03 11:39:39 UTC


README

GitHub Neo4j Version Support Packagist PHP Version Support (specify version) Packagist Version Packagist Downloads

Unit Tests Mutant Test Leak Tests PHPStan Psalm Code Style YML lint Markdown lint Test Coverage Maintainability

Syndesi's Cypher Entity Manager

This library provides an entity manager for Cypher data types.
This basically means, that you do not have to write create/merge/delete statements for your nodes, relations etc. per hand. Instead, you just call $em->create($node), $em->merge($node), $em->delete($node) and at the end $em->flush().

Installation

To install this library, run the following code:

composer require syndesi/cypher-entity-manager

This is all, now you can use the library :D

Using the library

use Syndesi\CypherDataStructures\Type\Node;
use Syndesi\CypherEntityManager\Type\EntityManager;

/**
 * note: the container should be provided by your framework. manual configuration is possible, see documentation
 * @var EntityManagerInterface $em 
 */
$em = $container->get(EntityManager::class);

$node = new Node();
$node
    ->addLabel('NodeLabel')
    ->addIdentifier('id', 123)
    ->addProperty('someProperty', 'someValue')
    ->addIdentifier('id');

// create a node:
$em->create($node);
$em->flush();

// update a node:
$node->addProperty('newProperty', 'Hello world :D');
$em->merge($node);
$em->flush();

// delete a node:
$em->delete($node);
$em->flush();