formal / orm
4.0.0
2024-10-31 15:16 UTC
Requires
- php: ~8.2
- formal/access-layer: ~4.0
- innmind/filesystem: ~7.4
- innmind/http-transport: ~7.2
- innmind/immutable: ~5.4
- innmind/json: ~1.3
- innmind/reflection: ~5.1
- innmind/specification: ~4.1
- innmind/time-continuum: ~3.3
- innmind/type: ~1.2
- innmind/url-template: ~3.1
- innmind/validation: ~1.4
- ramsey/uuid: ~4.7
Requires (Dev)
- innmind/black-box: ~5.1
- innmind/coding-standard: ~2.0
- innmind/operating-system: ~5.2
- vimeo/psalm: ~5.13
This package is auto-updated.
Last update: 2024-10-31 15:17:31 UTC
README
This ORM1 focuses to simplify data manipulation.
This is achieved by:
- using immutable objects
- each aggregate owning the objects it references
- using monads to fetch aggregates (from the Innmind ecosystem)
- using the specification pattern to match aggregates
This allows:
- simpler app design (as it can be pure)
- memory efficiency (the ORM doesn't keep objects in memory)
- long living processes (since there is no memory leaks)
- to work asynchronously
Installation
composer require formal/orm
Usage
use Formal\ORM\{ Manager, Sort, }; use Formal\AccessLayer\Connection\PDO; use Innmind\Url\Url; $manager = Manager::sql( PDO::of(Url::of('mysql://user:pwd@host:3306/database?charset=utf8mb4')), ); $_ = $manager ->repository(YourAggregate::class) ->all() ->sort('someProperty', Sort::asc) ->drop(150) ->take(50) ->foreach(static fn($aggregate) => doStuff($aggregate));
This simple example will retrieve from the database 50
elements (from index 151
to 200
) sorted by someProperty
in ascending order and will call the function doStuff
on each aggregate.
Note
The elements are streamed meaning only one aggregate is in memory at a time allowing you to deal with long lists of elements in a memory safe way.
Documentation
Full documentation available in the here.