Installation:
composer require concept-it/orient-db-bundle dev-master
Add the bundle to app/ApplicationKernel.php:
new ConceptIt\OrientDbBundle\ConceptItOrientDbBundle(),
Configure in config.yml:
concept_it_orient_db:
host: "127.0.0.1"
port: 2480
user: "root"
password: "password"
dbname: "test_db"
domain_dir: "%kernel.root_dir%/../src/AppBundle/Entity"
domain_namespace: "AppBundle\Entity"
First Use Case:
Define an entity (e.g., User) with @Document and @Field annotations (Doctrine ODM style).
Persist it via Symfony’s EntityManager:
$user = new User();
$user->setName('John Doe');
$em = $this->get('doctrine.odm.document_manager');
$em->persist($user);
$em->flush();
Entity Management:
DocumentManager (injected via doctrine.odm.document_manager service) for CRUD operations.// Fetch
$user = $em->find('User', 1);
// Update
$user->setName('Updated Name');
$em->flush();
// Delete
$em->remove($user);
$em->flush();
Querying:
QueryBuilder or Criteria:
$query = $em->createQueryBuilder('User')
->field('name')->equals('John Doe')->getQuery();
$users = $query->execute();
Event Listeners:
prePersist, postRemove) via EventManager:
$em->getEventManager()->addEventListener(
'prePersist',
function ($event) { /* Logic */ }
);
Custom Methods:
Persister/Remover by overriding the bundle’s services (e.g., in services.yml):
services:
concept_it_orient_db.persister:
class: AppBundle\Service\CustomPersister
arguments: ['@doctrine.odm.document_manager']
Namespace/Directory Mismatch:
domain_dir and domain_namespace in config match your entity paths.domain_dir points to the root of your Entity directory (e.g., src/AppBundle/Entity).Connection Issues:
dbname: null to auto-create.host, port, and credentials in config.Proxy Generation:
proxy_dir must be writable. Defaults to %kernel.root_dir%/cache.proxy_dir to a writable path (e.g., var/cache).Doctrine ODM Version:
composer.json:
"doctrine/doctrine-odm": "1.2.*"
Enable Logging:
Add to config.yml:
doctrine_odm:
logging: true
Check logs in var/logs/doctrine.log.
Query Debugging:
Use QueryBuilder::getQuery()->getDebugQuery() to inspect generated queries.
Schema Validation: Validate your schema with:
php bin/console doctrine:schema:validate
Bulk Operations:
Use DocumentManager::createBulkOperation() for batch inserts/updates:
$bulkOp = $em->createBulkOperation();
$bulkOp->insert($users);
$bulkOp->execute();
Custom Indexes:
Define indexes via @Index annotation or YAML:
# config.yml
doctrine_odm:
document_managers:
default:
mappings:
AppBundle\Entity\User:
indexes:
- name: "name_idx"
fields: ["name"]
Transaction Management: Wrap operations in transactions for atomicity:
$em->beginTransaction();
try {
$em->persist($user);
$em->flush();
$em->commit();
} catch (\Exception $e) {
$em->rollback();
throw $e;
}
How can I help you explore Laravel packages today?