Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/formal-php/orm
https://github.com/formal-php/orm
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/formal-php/orm
- Owner: formal-php
- License: mit
- Created: 2021-04-10T13:55:50.000Z (almost 4 years ago)
- Default Branch: develop
- Last Pushed: 2024-07-26T09:48:53.000Z (7 months ago)
- Last Synced: 2024-07-31T09:21:18.095Z (7 months ago)
- Language: PHP
- Homepage: https://formal-php.github.io/orm/
- Size: 2.49 MB
- Stars: 9
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ORM
[](https://github.com/formal-php/orm/actions?query=workflow%3ACI)
[](https://codecov.io/gh/formal-php/orm)
[](https://shepherd.dev/github/formal-php/orm)This ORM[^1] 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](https://github.com/Innmind) ecosystem)
- using the specification pattern to match aggregatesThis allows:
- simpler app design (as it can be [pure](https://innmind.github.io/documentation/philosophy/oop-fp/#purity))
- memory efficiency (the ORM doesn't keep objects in memory)
- long living processes (since there is no memory leaks)
- to work asynchronously## Installation
```sh
composer require formal/orm
```## Usage
```php
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](https://formal-php.github.io/orm/).
[^1]: Object Relational Mapping