PHPackages                             danog/async-orm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. danog/async-orm

ActiveLibrary

danog/async-orm
===============

Async ORM based on AMPHP v3 and fibers.

1.1.4(10mo ago)24198.9k—2.8%33Apache-2.0PHPPHP &gt;=8.2.4CI passing

Since Mar 31Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/danog/AsyncOrm)[ Packagist](https://packagist.org/packages/danog/async-orm)[ GitHub Sponsors](https://github.com/danog)[ RSS](/packages/danog-async-orm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (13)Versions (9)Used By (3)

Async ORM
=========

[](#async-orm)

[![codecov](https://camo.githubusercontent.com/16cb687a4e53a0cab7d83147078451f64bc7ed009840ca7934bbe94d9b8cf158/68747470733a2f2f636f6465636f762e696f2f67682f64616e6f672f4173796e634f726d2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/danog/AsyncOrm)[![Psalm coverage](https://camo.githubusercontent.com/fef4c24e6dfa1c8ae022fb565f0a02e1cb20cc2d7ff445357502694d92131c52/68747470733a2f2f73686570686572642e6465762f6769746875622f64616e6f672f4173796e634f726d2f636f7665726167652e737667)](https://shepherd.dev/github/danog/AsyncOrm)[![Psalm level 1](https://camo.githubusercontent.com/f73a6537e000f53699630a01cf87766f8f56c1d13ed9285416cc71bbe76ba789/68747470733a2f2f73686570686572642e6465762f6769746875622f64616e6f672f4173796e634f726d2f6c6576656c2e737667)](https://shepherd.dev/github/danog/AsyncOrm)[![License](https://camo.githubusercontent.com/75af1c5f768d6d10c27433500c26f7f4a5d93004ccbba231b92a8d96a41edc7b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f64616e6f672f4173796e634f726d)](https://camo.githubusercontent.com/75af1c5f768d6d10c27433500c26f7f4a5d93004ccbba231b92a8d96a41edc7b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f64616e6f672f4173796e634f726d)

Async PHP ORM based on AMPHP v3 and fibers, created by Daniil Gentili () and Alexander Pankratov ().

Supports MySQL, Redis, Postgres.

Features read and write-back caching, type-specific optimizations, and much more!

This ORM library was initially created for [MadelineProto](https://docs.madelineproto.xyz), an async PHP client API for the telegram MTProto protocol.

Installation
------------

[](#installation)

```
composer require danog/async-orm
```

Usage
-----

[](#usage)

There are two main ways to use the ORM: through automatic ORM properties, which automatically connects appropriately marked `DbArray` properties to the specified database, or by manually instantiating a `DbArray` with a `DbArrayBuilder`.

The `DbArray` obtained through one of the methods below is an abstract array object that automatically stores and fetches elements of the specified [type »](#value-types), from the specified database.

`DbArray`s of type `ValueType::OBJECT` can contain objects extending `DbObject`.

Classes extending `DbObject` have a special `save` method that can be used to persist object changes to the database, as can be seen in the [example](https://github.com/danog/AsyncOrm/blob/master/examples/2-manual.php).

### Automatic ORM properties example

[](#automatic-orm-properties-example)

```
