mirror of
https://github.com/danog/AsyncOrm.git
synced 2024-11-26 12:24:59 +01:00
Improve docs
This commit is contained in:
parent
05cc27c578
commit
e48420bf17
33
README.md
33
README.md
@ -1,7 +1,38 @@
|
||||
# Async ORM
|
||||
|
||||
Async ORM based on amphp.
|
||||
Async ORM based on amphp, created by Daniil Gentili <daniil@daniil.it> and Alexander Pankratov <alexander@i-c-a.su>.
|
||||
|
||||
Supports MySQL, Redis, Postgres.
|
||||
|
||||
Features read and write-back caching, type-specific optimizations, and much more!
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
composer require danog/async-orm
|
||||
```
|
||||
|
||||
## 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`.
|
||||
|
||||
* [Automatic ORM properties example »](https://github.com/danog/AsyncOrm/blob/master/examples/1-automatic.php)
|
||||
* [Manual example »](https://github.com/danog/AsyncOrm/blob/master/examples/2-manual.php)
|
||||
|
||||
The `DbArray` obtained through one of the methods above is an abstract array object that automatically stores and fetches elements from the specified database.
|
||||
|
||||
```php
|
||||
/** @var DbArray<TKey, TValue> $arr */
|
||||
|
||||
$value = $arr[$key];
|
||||
$arr[$key] = $newValue;
|
||||
|
||||
if (isset($arr[$otherKey])) {
|
||||
// Some logic
|
||||
unset($arr[$otherKey]);
|
||||
}
|
||||
```
|
||||
|
||||
## API Documentation
|
||||
|
||||
Click [here »](https://daniil.it/AsyncOrm/docs) to view the API documentation.
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
title: "danog\\AsyncOrm\\DbAutoProperties: "
|
||||
title: "danog\\AsyncOrm\\DbAutoProperties: Trait that provides autoconfiguration of OrmMappedArray properties."
|
||||
description: ""
|
||||
|
||||
---
|
||||
@ -10,7 +10,7 @@ description: ""
|
||||
> Author: Alexander Pankratov <alexander@i-c-a.su>
|
||||
|
||||
|
||||
|
||||
Trait that provides autoconfiguration of OrmMappedArray properties.
|
||||
|
||||
|
||||
|
41
docs/docs/index.md
Normal file
41
docs/docs/index.md
Normal file
@ -0,0 +1,41 @@
|
||||
---
|
||||
description: "Async ORM based on AMPHP v3 and fibers."
|
||||
title: "danog/async-orm"
|
||||
|
||||
---
|
||||
# `danog/async-orm`
|
||||
|
||||
Async ORM based on AMPHP v3 and fibers.
|
||||
|
||||
|
||||
|
||||
## Abstract classes
|
||||
* [\danog\AsyncOrm\DbArray: DB array interface.](danog/AsyncOrm/DbArray.md)
|
||||
* [\danog\AsyncOrm\DbObject](danog/AsyncOrm/DbObject.md)
|
||||
* [\danog\AsyncOrm\Serializer: Serializer interface.](danog/AsyncOrm/Serializer.md)
|
||||
* [\danog\AsyncOrm\Settings: Base interface for ORM settings.](danog/AsyncOrm/Settings.md)
|
||||
* [\danog\AsyncOrm\Driver\DriverArray: Base class for driver-based arrays.](danog/AsyncOrm/Driver/DriverArray.md)
|
||||
* [\danog\AsyncOrm\Driver\SqlArray: Generic SQL database backend.](danog/AsyncOrm/Driver/SqlArray.md)
|
||||
* [\danog\AsyncOrm\Settings\DriverSettings: Base settings class for database backends.](danog/AsyncOrm/Settings/DriverSettings.md)
|
||||
* [\danog\AsyncOrm\Settings\SqlSettings: Generic SQL db backend settings.](danog/AsyncOrm/Settings/SqlSettings.md)
|
||||
|
||||
## Classes
|
||||
* [\danog\AsyncOrm\FieldConfig: Contains configuration for a single ORM field.](danog/AsyncOrm/FieldConfig.md)
|
||||
* [\danog\AsyncOrm\KeyType: Specifies the type of keys.](danog/AsyncOrm/KeyType.md)
|
||||
* [\danog\AsyncOrm\ValueType: Specifies the serializer to use when saving values.](danog/AsyncOrm/ValueType.md)
|
||||
* [\danog\AsyncOrm\Annotations\OrmMappedArray: Attribute use to autoconfigure ORM properties.](danog/AsyncOrm/Annotations/OrmMappedArray.md)
|
||||
* [\danog\AsyncOrm\Driver\MemoryArray: Memory database backend.](danog/AsyncOrm/Driver/MemoryArray.md)
|
||||
* [\danog\AsyncOrm\Serializer\Igbinary: Igbinary serializer.](danog/AsyncOrm/Serializer/Igbinary.md)
|
||||
* [\danog\AsyncOrm\Serializer\Json: JSON serializer.](danog/AsyncOrm/Serializer/Json.md)
|
||||
* [\danog\AsyncOrm\Serializer\Native: Native serializer.](danog/AsyncOrm/Serializer/Native.md)
|
||||
* [\danog\AsyncOrm\Settings\MemorySettings: MemorySettings backend settings.](danog/AsyncOrm/Settings/MemorySettings.md)
|
||||
* [\danog\AsyncOrm\Settings\MysqlSettings: MySQL backend settings.](danog/AsyncOrm/Settings/MysqlSettings.md)
|
||||
* [\danog\AsyncOrm\Settings\PostgresSettings: Postgres backend settings.](danog/AsyncOrm/Settings/PostgresSettings.md)
|
||||
* [\danog\AsyncOrm\Settings\RedisSettings: Redis backend settings.](danog/AsyncOrm/Settings/RedisSettings.md)
|
||||
|
||||
## Traits
|
||||
* [\danog\AsyncOrm\DbAutoProperties: Trait that provides autoconfiguration of OrmMappedArray properties.](danog/AsyncOrm/DbAutoProperties.md)
|
||||
|
||||
|
||||
---
|
||||
Generated by [danog/phpdoc](https://phpdoc.daniil.it).
|
@ -1,41 +0,0 @@
|
||||
---
|
||||
description: "Async ORM based on AMPHP v3 and fibers."
|
||||
title: "danog/async-orm"
|
||||
|
||||
---
|
||||
# `danog/async-orm`
|
||||
|
||||
Async ORM based on AMPHP v3 and fibers.
|
||||
|
||||
|
||||
|
||||
## Abstract classes
|
||||
* [\danog\AsyncOrm\DbArray: DB array interface.](danog/AsyncOrm/DbArray.md)
|
||||
* [\danog\AsyncOrm\DbObject](danog/AsyncOrm/DbObject.md)
|
||||
* [\danog\AsyncOrm\Serializer: Serializer interface.](danog/AsyncOrm/Serializer.md)
|
||||
* [\danog\AsyncOrm\Settings: Base interface for ORM settings.](danog/AsyncOrm/Settings.md)
|
||||
* [\danog\AsyncOrm\Driver\DriverArray: Base class for driver-based arrays.](danog/AsyncOrm/Driver/DriverArray.md)
|
||||
* [\danog\AsyncOrm\Driver\SqlArray: Generic SQL database backend.](danog/AsyncOrm/Driver/SqlArray.md)
|
||||
* [\danog\AsyncOrm\Settings\DriverSettings: Base settings class for database backends.](danog/AsyncOrm/Settings/DriverSettings.md)
|
||||
* [\danog\AsyncOrm\Settings\SqlSettings: Generic SQL db backend settings.](danog/AsyncOrm/Settings/SqlSettings.md)
|
||||
|
||||
## Classes
|
||||
* [\danog\AsyncOrm\FieldConfig: Contains configuration for a single ORM field.](danog/AsyncOrm/FieldConfig.md)
|
||||
* [\danog\AsyncOrm\KeyType: Specifies the type of keys.](danog/AsyncOrm/KeyType.md)
|
||||
* [\danog\AsyncOrm\ValueType: Specifies the serializer to use when saving values.](danog/AsyncOrm/ValueType.md)
|
||||
* [\danog\AsyncOrm\Annotations\OrmMappedArray: Attribute use to autoconfigure ORM properties.](danog/AsyncOrm/Annotations/OrmMappedArray.md)
|
||||
* [\danog\AsyncOrm\Driver\MemoryArray: Memory database backend.](danog/AsyncOrm/Driver/MemoryArray.md)
|
||||
* [\danog\AsyncOrm\Serializer\Igbinary: Igbinary serializer.](danog/AsyncOrm/Serializer/Igbinary.md)
|
||||
* [\danog\AsyncOrm\Serializer\Json: JSON serializer.](danog/AsyncOrm/Serializer/Json.md)
|
||||
* [\danog\AsyncOrm\Serializer\Native: Native serializer.](danog/AsyncOrm/Serializer/Native.md)
|
||||
* [\danog\AsyncOrm\Settings\MemorySettings: MemorySettings backend settings.](danog/AsyncOrm/Settings/MemorySettings.md)
|
||||
* [\danog\AsyncOrm\Settings\MysqlSettings: MySQL backend settings.](danog/AsyncOrm/Settings/MysqlSettings.md)
|
||||
* [\danog\AsyncOrm\Settings\PostgresSettings: Postgres backend settings.](danog/AsyncOrm/Settings/PostgresSettings.md)
|
||||
* [\danog\AsyncOrm\Settings\RedisSettings: Redis backend settings.](danog/AsyncOrm/Settings/RedisSettings.md)
|
||||
|
||||
## Traits
|
||||
* [\danog\AsyncOrm\DbAutoProperties](danog/AsyncOrm/DbAutoProperties.md)
|
||||
|
||||
|
||||
---
|
||||
Generated by [danog/phpdoc](https://phpdoc.daniil.it).
|
1
docs/index.md
Symbolic link
1
docs/index.md
Symbolic link
@ -0,0 +1 @@
|
||||
../README.md
|
@ -6,7 +6,8 @@ use Amp\Redis\RedisConfig;
|
||||
use danog\AsyncOrm\Annotations\OrmMappedArray;
|
||||
use danog\AsyncOrm\DbArray;
|
||||
use danog\AsyncOrm\DbAutoProperties;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\DbArrayBuilder;
|
||||
use danog\AsyncOrm\DbObject;
|
||||
use danog\AsyncOrm\KeyType;
|
||||
use danog\AsyncOrm\Settings;
|
||||
use danog\AsyncOrm\Settings\MysqlSettings;
|
||||
@ -16,6 +17,8 @@ use danog\AsyncOrm\ValueType;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// Any of the following database backends can be used,
|
||||
// remove the ones you don't need.
|
||||
$settings = new MysqlSettings(
|
||||
new MysqlConfig(
|
||||
host: "/var/run/mysqld/mysqld.sock",
|
||||
@ -39,14 +42,24 @@ $settings = new RedisSettings(
|
||||
cacheTtl: 100
|
||||
);
|
||||
|
||||
$fieldConfig = new FieldConfig(
|
||||
'tableName',
|
||||
$settings,
|
||||
KeyType::STRING,
|
||||
ValueType::OBJECT
|
||||
);
|
||||
|
||||
$db = $fieldConfig->build();
|
||||
/**
|
||||
* An object stored in a database.
|
||||
*/
|
||||
class MyObject extends DbObject
|
||||
{
|
||||
public function __construct(
|
||||
private string $value
|
||||
) {
|
||||
}
|
||||
public function setValue(string $value): void
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
public function getValue(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main class of your application.
|
||||
@ -57,9 +70,19 @@ final class Application
|
||||
|
||||
/**
|
||||
* This field is automatically connected to the database using the specified Settings.
|
||||
*
|
||||
* @var DbArray<string, int>
|
||||
*/
|
||||
#[OrmMappedArray(KeyType::STRING, ValueType::INT)]
|
||||
private DbArray $dbProperty;
|
||||
private DbArray $dbProperty1;
|
||||
|
||||
/**
|
||||
* This field is automatically connected to the database using the specified Settings.
|
||||
*
|
||||
* @var DbArray<string, MyObject>
|
||||
*/
|
||||
#[OrmMappedArray(KeyType::STRING, ValueType::OBJECT)]
|
||||
private DbArray $dbProperty2;
|
||||
|
||||
public function __construct(
|
||||
Settings $settings,
|
||||
@ -70,8 +93,23 @@ final class Application
|
||||
|
||||
public function businessLogic(): void
|
||||
{
|
||||
$this->dbProperty['someKey'] = 123;
|
||||
var_dump($this->dbProperty['someKey']);
|
||||
// Can store integers, strings, arrays or objects depending on the specified ValueType
|
||||
$this->dbProperty1['someKey'] = 123;
|
||||
var_dump($this->dbProperty1['someKey']);
|
||||
|
||||
$this->dbProperty2['someOtherKey'] = new MyObject("initialValue");
|
||||
}
|
||||
|
||||
public function businessLogic2(string $value): void
|
||||
{
|
||||
$obj = $this->dbProperty2['someOtherKey'];
|
||||
$obj->setValue($value);
|
||||
$obj->save();
|
||||
}
|
||||
|
||||
public function businessLogic3(): string
|
||||
{
|
||||
return $this->dbProperty2['someOtherKey']->getValue();
|
||||
}
|
||||
|
||||
public function shutdown(): void
|
||||
@ -83,4 +121,6 @@ final class Application
|
||||
|
||||
$app = new Application($settings, 'tablePrefix');
|
||||
$app->businessLogic();
|
||||
$app->businessLogic2("newValue");
|
||||
var_dump($app->businessLogic3());
|
||||
$app->shutdown();
|
@ -4,7 +4,7 @@ use Amp\Mysql\MysqlConfig;
|
||||
use Amp\Postgres\PostgresConfig;
|
||||
use Amp\Redis\RedisConfig;
|
||||
use danog\AsyncOrm\DbObject;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\DbArrayBuilder;
|
||||
use danog\AsyncOrm\KeyType;
|
||||
use danog\AsyncOrm\Settings\MysqlSettings;
|
||||
use danog\AsyncOrm\Settings\PostgresSettings;
|
||||
@ -13,6 +13,8 @@ use danog\AsyncOrm\ValueType;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// Any of the following database backends can be used,
|
||||
// remove the ones you don't need.
|
||||
$settings = new MysqlSettings(
|
||||
new MysqlConfig(
|
||||
host: "/var/run/mysqld/mysqld.sock",
|
||||
@ -36,7 +38,7 @@ $settings = new RedisSettings(
|
||||
cacheTtl: 100
|
||||
);
|
||||
|
||||
$fieldConfig = new FieldConfig(
|
||||
$fieldConfig = new DbArrayBuilder(
|
||||
'tableName',
|
||||
$settings,
|
||||
KeyType::STRING,
|
@ -119,5 +119,5 @@ abstract class DbArray implements Countable, ArrayAccess, Traversable, IteratorA
|
||||
/**
|
||||
* Get instance.
|
||||
*/
|
||||
abstract public static function getInstance(FieldConfig $config, self|null $previous): self;
|
||||
abstract public static function getInstance(DbArrayBuilder $config, self|null $previous): self;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
* @license https://opensource.org/license/apache-2-0 Apache 2.0
|
||||
* @link https://daniil.it/AsyncOrm AsyncOrm documentation
|
||||
*/
|
||||
|
||||
namespace danog\AsyncOrm;
|
||||
|
||||
use AssertionError;
|
||||
@ -29,11 +30,11 @@ use danog\AsyncOrm\Settings\DriverSettings;
|
||||
use danog\AsyncOrm\Settings\MemorySettings;
|
||||
|
||||
/**
|
||||
* Contains configuration for a single ORM field.
|
||||
* Contains configuration needed to build a DbArray.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
final readonly class FieldConfig
|
||||
final readonly class DbArrayBuilder
|
||||
{
|
||||
public function __construct(
|
||||
/**
|
@ -34,7 +34,11 @@ use ReflectionClass;
|
||||
use function Amp\async;
|
||||
use function Amp\Future\await;
|
||||
|
||||
/** @api */
|
||||
/**
|
||||
* Trait that provides autoconfiguration of OrmMappedArray properties.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
trait DbAutoProperties
|
||||
{
|
||||
/** @var list<CachedArray> */
|
||||
@ -74,7 +78,7 @@ trait DbAutoProperties
|
||||
}
|
||||
}
|
||||
|
||||
$config = new FieldConfig(
|
||||
$config = new DbArrayBuilder(
|
||||
$tablePrefix.($attr->tablePostfix ?? $property->getName()),
|
||||
$settings,
|
||||
$attr->keyType,
|
||||
|
@ -39,7 +39,7 @@ abstract class DbObject
|
||||
*
|
||||
* @internal Do not invoke manually.
|
||||
*/
|
||||
final public function initDb(ObjectContainer $mapper, string|int $key, FieldConfig $config): void
|
||||
final public function initDb(ObjectContainer $mapper, string|int $key, DbArrayBuilder $config): void
|
||||
{
|
||||
$this->mapper = $mapper;
|
||||
$this->key = $key;
|
||||
@ -65,7 +65,7 @@ abstract class DbObject
|
||||
*
|
||||
* @psalm-suppress PossiblyUnusedParam
|
||||
*/
|
||||
protected function onLoaded(FieldConfig $config): void
|
||||
protected function onLoaded(DbArrayBuilder $config): void
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
namespace danog\AsyncOrm\Driver;
|
||||
|
||||
use danog\AsyncOrm\DbArray;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\DbArrayBuilder;
|
||||
use danog\AsyncOrm\Serializer;
|
||||
use danog\AsyncOrm\Settings\DriverSettings;
|
||||
|
||||
@ -52,13 +52,13 @@ abstract class DriverArray extends DbArray
|
||||
* @param Serializer<TValue> $serializer
|
||||
*/
|
||||
protected function __construct(
|
||||
protected readonly FieldConfig $config,
|
||||
protected readonly DbArrayBuilder $config,
|
||||
protected readonly Serializer $serializer
|
||||
) {
|
||||
$this->inited = true;
|
||||
}
|
||||
|
||||
public static function getInstance(FieldConfig $config, DbArray|null $previous): DbArray
|
||||
public static function getInstance(DbArrayBuilder $config, DbArray|null $previous): DbArray
|
||||
{
|
||||
$migrate = true;
|
||||
if ($previous !== null
|
||||
|
@ -27,7 +27,7 @@ namespace danog\AsyncOrm\Driver;
|
||||
|
||||
use ArrayIterator;
|
||||
use danog\AsyncOrm\DbArray;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\DbArrayBuilder;
|
||||
|
||||
/**
|
||||
* Memory database backend.
|
||||
@ -45,7 +45,7 @@ final class MemoryArray extends DbArray
|
||||
) {
|
||||
}
|
||||
|
||||
public static function getInstance(FieldConfig $config, DbArray|null $previous): DbArray
|
||||
public static function getInstance(DbArrayBuilder $config, DbArray|null $previous): DbArray
|
||||
{
|
||||
if ($previous instanceof self) {
|
||||
return $previous;
|
||||
|
@ -27,7 +27,7 @@ namespace danog\AsyncOrm\Driver;
|
||||
|
||||
use Amp\Sql\SqlConnectionPool;
|
||||
use Amp\Sql\SqlResult;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\DbArrayBuilder;
|
||||
use danog\AsyncOrm\Serializer;
|
||||
|
||||
/**
|
||||
@ -46,7 +46,7 @@ abstract class SqlArray extends DriverArray
|
||||
* @param Serializer<TValue> $serializer
|
||||
*/
|
||||
protected function __construct(
|
||||
FieldConfig $config,
|
||||
DbArrayBuilder $config,
|
||||
Serializer $serializer,
|
||||
protected readonly SqlConnectionPool $db,
|
||||
private readonly string $get,
|
||||
|
@ -21,7 +21,7 @@ namespace danog\AsyncOrm\Internal\Containers;
|
||||
use Amp\Sync\LocalMutex;
|
||||
use danog\AsyncOrm\DbArray;
|
||||
use danog\AsyncOrm\DbObject;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\DbArrayBuilder;
|
||||
use Revolt\EventLoop;
|
||||
use Traversable;
|
||||
|
||||
@ -47,7 +47,7 @@ final class ObjectContainer
|
||||
public function __construct(
|
||||
/** @var DbArray<TKey, TValue> */
|
||||
public DbArray $inner,
|
||||
public FieldConfig $config,
|
||||
public DbArrayBuilder $config,
|
||||
public int $cacheTtl,
|
||||
) {
|
||||
$this->mutex = new LocalMutex;
|
||||
|
@ -26,7 +26,7 @@
|
||||
namespace danog\AsyncOrm\Internal\Driver;
|
||||
|
||||
use danog\AsyncOrm\DbArray;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\DbArrayBuilder;
|
||||
use danog\AsyncOrm\Internal\Containers\CacheContainer;
|
||||
use danog\AsyncOrm\Settings\DriverSettings;
|
||||
use Revolt\EventLoop;
|
||||
@ -51,7 +51,7 @@ final class CachedArray extends DbArray
|
||||
/**
|
||||
* Get instance.
|
||||
*/
|
||||
public static function getInstance(FieldConfig $config, DbArray|null $previous): DbArray
|
||||
public static function getInstance(DbArrayBuilder $config, DbArray|null $previous): DbArray
|
||||
{
|
||||
\assert($config->settings instanceof DriverSettings);
|
||||
$new = $config->settings->getDriverClass();
|
||||
|
@ -31,7 +31,7 @@ use Amp\Sync\LocalKeyedMutex;
|
||||
use AssertionError;
|
||||
use danog\AsyncOrm\Driver\Mysql;
|
||||
use danog\AsyncOrm\Driver\SqlArray;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\DbArrayBuilder;
|
||||
use danog\AsyncOrm\Internal\Serializer\BoolInt;
|
||||
use danog\AsyncOrm\Internal\Serializer\Passthrough;
|
||||
use danog\AsyncOrm\KeyType;
|
||||
@ -63,7 +63,7 @@ final class MysqlArray extends SqlArray
|
||||
* @psalm-suppress MethodSignatureMismatch
|
||||
* @param Serializer<TValue> $serializer
|
||||
*/
|
||||
public function __construct(FieldConfig $config, Serializer $serializer)
|
||||
public function __construct(DbArrayBuilder $config, Serializer $serializer)
|
||||
{
|
||||
$settings = $config->settings;
|
||||
\assert($settings instanceof \danog\AsyncOrm\Settings\MysqlSettings);
|
||||
|
@ -28,7 +28,7 @@ namespace danog\AsyncOrm\Internal\Driver;
|
||||
use danog\AsyncOrm\DbArray;
|
||||
use danog\AsyncOrm\DbObject;
|
||||
use danog\AsyncOrm\Driver\MemoryArray;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\DbArrayBuilder;
|
||||
use danog\AsyncOrm\Internal\Containers\ObjectContainer;
|
||||
use danog\AsyncOrm\Settings\DriverSettings;
|
||||
use Traversable;
|
||||
@ -51,7 +51,7 @@ final class ObjectArray extends DbArray
|
||||
/**
|
||||
* Get instance.
|
||||
*/
|
||||
public static function getInstance(FieldConfig $config, DbArray|null $previous): DbArray
|
||||
public static function getInstance(DbArrayBuilder $config, DbArray|null $previous): DbArray
|
||||
{
|
||||
$new = $config->settings->getDriverClass();
|
||||
\assert($config->settings instanceof DriverSettings);
|
||||
@ -76,7 +76,7 @@ final class ObjectArray extends DbArray
|
||||
}
|
||||
|
||||
/** @param DbArray<TKey, TValue> $inner */
|
||||
public function __construct(DbArray $inner, FieldConfig $config, int $cacheTtl)
|
||||
public function __construct(DbArray $inner, DbArrayBuilder $config, int $cacheTtl)
|
||||
{
|
||||
$this->cache = new ObjectContainer($inner, $config, $cacheTtl);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ namespace danog\AsyncOrm\Internal\Driver;
|
||||
use Amp\Postgres\PostgresConnectionPool;
|
||||
use Amp\Sync\LocalKeyedMutex;
|
||||
use danog\AsyncOrm\Driver\SqlArray;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\DbArrayBuilder;
|
||||
use danog\AsyncOrm\Internal\Serializer\ByteaSerializer;
|
||||
use danog\AsyncOrm\Internal\Serializer\Passthrough;
|
||||
use danog\AsyncOrm\KeyType;
|
||||
@ -55,7 +55,7 @@ class PostgresArray extends SqlArray
|
||||
* @psalm-suppress MethodSignatureMismatch
|
||||
* @param Serializer<TValue> $serializer
|
||||
*/
|
||||
public function __construct(FieldConfig $config, Serializer $serializer)
|
||||
public function __construct(DbArrayBuilder $config, Serializer $serializer)
|
||||
{
|
||||
self::$mutex ??= new LocalKeyedMutex;
|
||||
$settings = $config->settings;
|
||||
|
@ -29,7 +29,7 @@ use Amp\Redis\Connection\ReconnectingRedisLink;
|
||||
use Amp\Redis\RedisClient;
|
||||
use Amp\Sync\LocalKeyedMutex;
|
||||
use danog\AsyncOrm\Driver\DriverArray;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\DbArrayBuilder;
|
||||
use danog\AsyncOrm\Internal\Serializer\BoolString;
|
||||
use danog\AsyncOrm\Internal\Serializer\FloatString;
|
||||
use danog\AsyncOrm\Internal\Serializer\IntString;
|
||||
@ -64,7 +64,7 @@ final class RedisArray extends DriverArray
|
||||
* @api
|
||||
* @param Serializer<TValue> $serializer
|
||||
*/
|
||||
public function __construct(FieldConfig $config, Serializer $serializer)
|
||||
public function __construct(DbArrayBuilder $config, Serializer $serializer)
|
||||
{
|
||||
/** @var Serializer<TValue> */
|
||||
$serializer = match ($config->valueType) {
|
||||
|
@ -32,7 +32,7 @@ use Amp\Redis\RedisConfig;
|
||||
use AssertionError;
|
||||
use danog\AsyncOrm\DbObject;
|
||||
use danog\AsyncOrm\Driver\MemoryArray;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\DbArrayBuilder;
|
||||
use danog\AsyncOrm\Internal\Driver\CachedArray;
|
||||
use danog\AsyncOrm\Internal\Driver\ObjectArray;
|
||||
use danog\AsyncOrm\KeyType;
|
||||
@ -149,7 +149,7 @@ final class OrmTest extends TestCase
|
||||
#[DataProvider('provideSettingsKeysValues')]
|
||||
public function testBasic(int $tablePostfix, Settings $settings, KeyType $keyType, string|int $key, ValueType $valueType, mixed $value): void
|
||||
{
|
||||
$field = new FieldConfig(
|
||||
$field = new DbArrayBuilder(
|
||||
"testBasic_$tablePostfix",
|
||||
$settings,
|
||||
$keyType,
|
||||
@ -265,7 +265,7 @@ final class OrmTest extends TestCase
|
||||
#[DataProvider('provideSettings')]
|
||||
public function testKeyMigration(int $tablePostfix, Settings $settings): void
|
||||
{
|
||||
$field = new FieldConfig(
|
||||
$field = new DbArrayBuilder(
|
||||
$table = 'testKeyMigration_'.$tablePostfix,
|
||||
$settings,
|
||||
KeyType::STRING_OR_INT,
|
||||
@ -288,7 +288,7 @@ final class OrmTest extends TestCase
|
||||
return;
|
||||
}
|
||||
|
||||
$field = new FieldConfig(
|
||||
$field = new DbArrayBuilder(
|
||||
$table,
|
||||
$settings,
|
||||
KeyType::INT,
|
||||
@ -305,7 +305,7 @@ final class OrmTest extends TestCase
|
||||
}
|
||||
$this->assertEquals(1, $cnt);
|
||||
|
||||
$field = new FieldConfig(
|
||||
$field = new DbArrayBuilder(
|
||||
$table,
|
||||
$settings,
|
||||
KeyType::STRING,
|
||||
@ -323,7 +323,7 @@ final class OrmTest extends TestCase
|
||||
}
|
||||
$this->assertEquals(1, $cnt);
|
||||
|
||||
$field = new FieldConfig(
|
||||
$field = new DbArrayBuilder(
|
||||
$table,
|
||||
$settings,
|
||||
KeyType::INT,
|
||||
@ -341,7 +341,7 @@ final class OrmTest extends TestCase
|
||||
}
|
||||
$this->assertEquals(1, $cnt);
|
||||
|
||||
$field = new FieldConfig(
|
||||
$field = new DbArrayBuilder(
|
||||
$table.'_new',
|
||||
$settings,
|
||||
KeyType::INT,
|
||||
@ -359,7 +359,7 @@ final class OrmTest extends TestCase
|
||||
}
|
||||
$this->assertEquals(1, $cnt);
|
||||
|
||||
$field = new FieldConfig(
|
||||
$field = new DbArrayBuilder(
|
||||
$table.'_new',
|
||||
new MemorySettings,
|
||||
KeyType::INT,
|
||||
@ -390,7 +390,7 @@ final class OrmTest extends TestCase
|
||||
if ($settings->serializer instanceof Json) {
|
||||
$this->expectExceptionMessage("The JSON backend cannot be used when serializing objects!");
|
||||
}
|
||||
$field = new FieldConfig(
|
||||
$field = new DbArrayBuilder(
|
||||
'testObject_'.$tablePostfix,
|
||||
$settings,
|
||||
KeyType::STRING_OR_INT,
|
||||
@ -488,11 +488,11 @@ final class OrmTest extends TestCase
|
||||
|
||||
public function testCache(): void
|
||||
{
|
||||
$field = new FieldConfig("testCache", new RedisSettings(
|
||||
$field = new DbArrayBuilder("testCache", new RedisSettings(
|
||||
RedisConfig::fromUri("redis://127.0.0.1"),
|
||||
cacheTtl: 1
|
||||
), KeyType::INT, ValueType::INT);
|
||||
$fieldNoCache = new FieldConfig("testCache", new RedisSettings(
|
||||
$fieldNoCache = new DbArrayBuilder("testCache", new RedisSettings(
|
||||
RedisConfig::fromUri("redis://127.0.0.1"),
|
||||
cacheTtl: 0
|
||||
), KeyType::INT, ValueType::INT);
|
||||
|
@ -27,7 +27,7 @@ use danog\AsyncOrm\Annotations\OrmMappedArray;
|
||||
use danog\AsyncOrm\DbArray;
|
||||
use danog\AsyncOrm\DbAutoProperties;
|
||||
use danog\AsyncOrm\DbObject;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\DbArrayBuilder;
|
||||
use danog\AsyncOrm\KeyType;
|
||||
use danog\AsyncOrm\ValueType;
|
||||
|
||||
@ -57,7 +57,7 @@ final class TestObject extends DbObject
|
||||
return ['savedProp', 'arr'];
|
||||
}
|
||||
|
||||
protected function onLoaded(FieldConfig $config): void
|
||||
protected function onLoaded(DbArrayBuilder $config): void
|
||||
{
|
||||
$this->initDbProperties($config->settings, $config->table);
|
||||
$this->loadedCnt++;
|
||||
|
Loading…
Reference in New Issue
Block a user