formal / orm
Requires
- php: ~8.2
- formal/access-layer: ~2.15
- innmind/filesystem: ~7.4
- innmind/http-transport: ~7.2
- innmind/immutable: ~4.15|~5.0
- innmind/json: ~1.3
- innmind/reflection: ~5.1
- innmind/specification: ~3.0
- innmind/time-continuum: ~3.3
- innmind/type: ~1.2
- innmind/url-template: ~3.1
- innmind/validation: ^1.1.1
- ramsey/uuid: ~4.7
Requires (Dev)
- innmind/black-box: ~5.1
- innmind/coding-standard: ~2.0
- innmind/operating-system: ~4.2
- vimeo/psalm: ~5.13
This package is auto-updated.
Last update: 2024-04-25 14:35:36 UTC
README
This ORM (Object-Relational Mapping) is focused to work in long living processes and being able to work in an asynchronous context.
This is achieved by:
- being memory efficient (objects are not kept in memory)
- relying on the Innmind platform
- using immutable objects
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 documentation folder.
Benchmark
A small benchmark as a reference point for the performance of this ORM consists in generating and persisting 100K users in a single transaction and then loading them.
time php benchmark/fill_storage.php php benchmark/fill_storage.php 222.24s user 5.20s system 60% cpu 6:18.40 total time php benchmark/load.php Memory: 40.00 Mo php benchmark/load.php 11.06s user 0.08s system 97% cpu 11.388 total
This means the ORM can load 1 aggregate in 0.1 millisecond.
This was run on a MacbookPro 16" with a M1 Max with the mariadb running inside Docker.
Note: If all the aggregates were to be stored in memory it would take around 2Go of RAM and 15 seconds to complete.