g4 / data-repository
repository php library
Installs: 50 815
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 12
Forks: 5
Open Issues: 1
Requires
- php: >=8.2
- g4/data-mapper: 2.0.*
- g4/identity-map: >=1.3.0
- g4/russian-doll: >=0.4.5
Requires (Dev)
- g4/code-coverage: 1.*
- phpunit/phpunit: 9.*
- squizlabs/php_codesniffer: 3.*
README
data-repository - repository library for php.
- database storage with data-mapper
- caching with russian-doll
- in-memory data store with identity-map
Install
Install through composer package manager. Find it on packagist.
composer require g4/data-repository
Dependencies:
Usage
Check data-mapper docs for details - data-mapper
Check russian-doll docs for details - russian-doll
Check identity-map docs for details - identity-map
use G4\DataMapper\Builder; use G4\DataMapper\Common\Identity; use G4\DataMapper\Common\MappingInterface; use G4\DataMapper\Engine\MySQL\MySQLAdapter; use G4\DataMapper\Engine\MySQL\MySQLClientFactory; use G4\DataRepository\DataRepositoryFactory; use G4\IdentityMap\IdentityMap; use G4\Mcache\McacheFactory; use G4\RussianDoll\Key; use G4\RussianDoll\RussianDoll; // Create instance $dataRepository = (new DataRepositoryFactory( Builder::create()->adapter(new MySQLAdapter(new MySQLClientFactory([]))), new RussianDoll(McacheFactory::createInstance('__driver_name__', [], '__prefix__')), new IdentityMap() ))->create(); // Read flow with: data-mapper's mysql engine, russian-doll and identity-map $identity = new Identity(); $identity ->field('__field_name__') ->equal('__field_value__'); $response = $dataRepository ->setDatasetName('__table_name__') ->setIdentity($identity) ->setIdentityMapKey('__table_name__', '__field_name__', '__field_value__') ->setRussianDollKey(new Key('__table_name__', '__field_name__', '__field_value__')) ->select(); // Write flow (insert, update, upsert, delete) with: data-mapper's mysql engine, russian-doll, and identity-map $identity = new Identity(); $identity ->field('__field_name__') ->equal('__field_value__'); $this->repository ->setDatasetName('__table_name__') ->setMapping(new Mapp())) // must implement mapping ->insert(); $dataRepository ->setDatasetName('__table_name__') ->setIdentity($identity) ->setIdentityMapKey('__table_name__', '__field_name__', '__field_value__') ->setRussianDollKey(new Key('__table_name__', '__field_name__', '__field_value__')) ->setMapping(new Mapp())) // must implement mapping ->update(); $this->repository ->setDatasetName('__table_name__') ->setIdentity($identity) ->setIdentityMapKey('__table_name__', '__field_name__', '__field_value__') ->setRussianDollKey(new Key('__table_name__', '__field_name__', '__field_value__')) ->setMapping(new Mapp())) // must implement mapping ->upsert(); $this->repository ->setDatasetName('__table_name__') ->setIdentity($identity) ->setIdentityMapKey('__table_name__', '__field_name__', '__field_value__') ->setRussianDollKey(new Key('__table_name__', '__field_name__', '__field_value__')) ->delete(); $this->repository ->setDatasetName('__table_name__') ->setIdentityMapKey('__table_name__') ->setRussianDollKey(new Key('__table_name__')) ->query('SELECT * FROM __table_name__'); $this->repository ->setDatasetName('__table_name__') ->setIdentityMapKey('__table_name__', '__field_name__', '__field_value__') ->setRussianDollKey(new Key('__table_name__', '__field_name__', '__field_value__')) ->command('DELETE FROM __table_name__ WHERE __field_name__ = __field_value__');
Development
Install dependencies
$ composer install
Run tests
$ composer unit-test
License
(The MIT License) see LICENSE file for details...