<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
morebec / orkestra-postgresql-document-store example snippets
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;
use Morebec\Orkestra\DateTime\SystemClock;
use Morebec\Orkestra\PostgreSqlDocumentStore\PostgreSqlDocumentStore;
use Morebec\Orkestra\PostgreSqlDocumentStore\PostgreSqlDocumentStoreConfiguration;
$connection = DriverManager::getConnection([
'url' => '...'
], new Configuration());
$config = new PostgreSqlDocumentStoreConfiguration();
$clock = new SystemClock();
$store = new PostgreSqlDocumentStore($connection, $config, $clock);
use Morebec\Orkestra\PostgreSqlDocumentStore\Filter\Filter;
use Morebec\Orkestra\PostgreSqlDocumentStore\Filter\FilterOperator;
$store->insertDocument('users', 'usr123456789', [
'id' => 'usr123456789',
'username' => 'jane.doe',
'fullname' => 'Jane Doe',
'emailAddress' => '[email protected]',
'preferredLanguage' => 'ENGLISH'
]);
// Finds a document by its ID.
$store->findOneDocument('users', Filter::findById('usr123456789'));
// Finds a document by a single field:
$store->findOneDocument('users', Filter::findByField('username', FilterOperator::EQUAL(), 'jane.doe'));
// Finds a document by a multiple criteria
$store->findOneDocument('users',
Filter::where('username', FilterOperator::EQUAL(), 'jane.doe')
->or('preferredLanguage', FilterOperator::IS_NOT(), null)
);
// You can also use strings to have greater control over the query:
$store->findOneDocument('users', 'data->>fullname = \'Jane Doe\'');
use Morebec\Orkestra\PostgreSqlDocumentStore\PostgreSqlDocumentStore;
/** @var $store PostgreSqlDocumentStore **/
$store->removeDocument('users', 'usr123456789');
use Morebec\Orkestra\PostgreSqlDocumentStore\PostgreSqlDocumentStoreConfiguration;
$config = new PostgreSqlDocumentStoreConfiguration();
$config->collectionPrefix = 'you_prefix_';