Download the PHP package danog/async-orm without Composer
On this page you can find all versions of the php package danog/async-orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download danog/async-orm
More information about danog/async-orm
Files in danog/async-orm
Package async-orm
Short Description Async ORM based on AMPHP v3 and fibers.
License Apache-2.0
Informations about the package async-orm
Async ORM
Async PHP ORM based on AMPHP v3 and fibers, created by Daniil Gentili (https://daniil.it) and Alexander Pankratov (https://github.com/xtrime-ru).
Supports MySQL, Redis, Postgres.
Features read and write-back caching, type-specific optimizations, and much more!
This ORM library was initially created for MadelineProto, an async PHP client API for the telegram MTProto protocol.
Installation
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 », 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.
Automatic ORM properties example
Manual ORM properties example
See here »
Settings
As specified in the examples above, there are multiple settings classes that can be used to connect to a specific database type:
- MysqlSettings: MySQL backend settings.
- PostgresSettings: Postgres backend settings.
- RedisSettings: Redis backend settings.
All these classes have multiple fields, described in their respective documentation (click on each class name to view it).
Caching
One of the most important settings is the cacheTtl
field, which specifies the duration of the read and write cache.
If non-zero, all array elements fetched from the database will be stored in an in-memory read cache for the specified number of seconds; multiple accesses to the same field will each postpone flushing of that field by cacheTtl
seconds.
All elements written to the array by the application will also be stored in an in-memory write cache, and flushed to the database every cacheTtl
seconds.
The cache is also flushed on shutdown by deferring an event loop callback, so make sure EventLoop::run();
is being used to run the application, to make sure all data is flushed correctly (alternatively, saveDbProperties
can be used to manually flush the cache on shutdown when using automatic properties, and flushCache
in manual mode).
If the array has an object value type (ValueType::OBJECT), write caching is disabled.
If cacheTtl
is 0, read and write caching is disabled.
A special setting class is used to create DbArray
s backed by no database, which can also be useful in certain circumstances:
Key and value types
Each DbArray must have a specific key and value type.
For optimal performance, the specified types must be as strict as possible, here's a list of allowed types:
Key types
KeyType::STRING
- String keys onlyKeyType::INT
- Integer keys onlyKeyType::STRING_OR_INT
- String or integer keys (not recommended, for performance reasons please always specify eitherSTRING
orSTRING_OR_INT
).
Value types
ValueType::STRING
: Direct storage of UTF-8 string values.ValueType::INT
: Direct storage of integer values.ValueType::BOOL
: Direct storage of boolean values.ValueType::FLOAT
: Direct storage of floating point (double precision) values.ValueType::SCALAR
: Values of any scalar type (including blobs and arrays, excluding objects), serialized as specified in the settings. Using SCALAR worsens performances, please use any of the other types if possible.ValueType::OBJECT
: Objects extending DbObject, serialized as specified in the settings.
One of the most important value types is ValueType::OBJECT
, it is used to store entire objects extending the DbObject
class to the database.
Objects 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.
API Documentation
Click here » to view the API documentation.
All versions of async-orm with dependencies
amphp/mysql Version ^3.0
amphp/postgres Version ^2.0
amphp/redis Version ^2.0
amphp/sync Version ^2.2
revolt/event-loop Version ^1.0.6