diff --git a/README.md b/README.md index 2e217fc..b2574fc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,38 @@ # Async ORM -Async ORM based on amphp. +Async ORM based on amphp, created by Daniil Gentili and Alexander Pankratov . Supports MySQL, Redis, Postgres. -Features read and write-back caching, type-specific optimizations, and much more! \ No newline at end of file +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 $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. diff --git a/docs/danog/AsyncOrm/Annotations/OrmMappedArray.md b/docs/docs/danog/AsyncOrm/Annotations/OrmMappedArray.md similarity index 100% rename from docs/danog/AsyncOrm/Annotations/OrmMappedArray.md rename to docs/docs/danog/AsyncOrm/Annotations/OrmMappedArray.md diff --git a/docs/danog/AsyncOrm/DbArray.md b/docs/docs/danog/AsyncOrm/DbArray.md similarity index 100% rename from docs/danog/AsyncOrm/DbArray.md rename to docs/docs/danog/AsyncOrm/DbArray.md diff --git a/docs/danog/AsyncOrm/DbAutoProperties.md b/docs/docs/danog/AsyncOrm/DbAutoProperties.md similarity index 83% rename from docs/danog/AsyncOrm/DbAutoProperties.md rename to docs/docs/danog/AsyncOrm/DbAutoProperties.md index 73e1d13..143fed9 100644 --- a/docs/danog/AsyncOrm/DbAutoProperties.md +++ b/docs/docs/danog/AsyncOrm/DbAutoProperties.md @@ -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 - +Trait that provides autoconfiguration of OrmMappedArray properties. diff --git a/docs/danog/AsyncOrm/DbObject.md b/docs/docs/danog/AsyncOrm/DbObject.md similarity index 100% rename from docs/danog/AsyncOrm/DbObject.md rename to docs/docs/danog/AsyncOrm/DbObject.md diff --git a/docs/danog/AsyncOrm/Driver/DriverArray.md b/docs/docs/danog/AsyncOrm/Driver/DriverArray.md similarity index 100% rename from docs/danog/AsyncOrm/Driver/DriverArray.md rename to docs/docs/danog/AsyncOrm/Driver/DriverArray.md diff --git a/docs/danog/AsyncOrm/Driver/MemoryArray.md b/docs/docs/danog/AsyncOrm/Driver/MemoryArray.md similarity index 100% rename from docs/danog/AsyncOrm/Driver/MemoryArray.md rename to docs/docs/danog/AsyncOrm/Driver/MemoryArray.md diff --git a/docs/danog/AsyncOrm/Driver/SqlArray.md b/docs/docs/danog/AsyncOrm/Driver/SqlArray.md similarity index 100% rename from docs/danog/AsyncOrm/Driver/SqlArray.md rename to docs/docs/danog/AsyncOrm/Driver/SqlArray.md diff --git a/docs/danog/AsyncOrm/FieldConfig.md b/docs/docs/danog/AsyncOrm/FieldConfig.md similarity index 100% rename from docs/danog/AsyncOrm/FieldConfig.md rename to docs/docs/danog/AsyncOrm/FieldConfig.md diff --git a/docs/danog/AsyncOrm/KeyType.md b/docs/docs/danog/AsyncOrm/KeyType.md similarity index 100% rename from docs/danog/AsyncOrm/KeyType.md rename to docs/docs/danog/AsyncOrm/KeyType.md diff --git a/docs/danog/AsyncOrm/Serializer.md b/docs/docs/danog/AsyncOrm/Serializer.md similarity index 100% rename from docs/danog/AsyncOrm/Serializer.md rename to docs/docs/danog/AsyncOrm/Serializer.md diff --git a/docs/danog/AsyncOrm/Serializer/Igbinary.md b/docs/docs/danog/AsyncOrm/Serializer/Igbinary.md similarity index 100% rename from docs/danog/AsyncOrm/Serializer/Igbinary.md rename to docs/docs/danog/AsyncOrm/Serializer/Igbinary.md diff --git a/docs/danog/AsyncOrm/Serializer/Json.md b/docs/docs/danog/AsyncOrm/Serializer/Json.md similarity index 100% rename from docs/danog/AsyncOrm/Serializer/Json.md rename to docs/docs/danog/AsyncOrm/Serializer/Json.md diff --git a/docs/danog/AsyncOrm/Serializer/Native.md b/docs/docs/danog/AsyncOrm/Serializer/Native.md similarity index 100% rename from docs/danog/AsyncOrm/Serializer/Native.md rename to docs/docs/danog/AsyncOrm/Serializer/Native.md diff --git a/docs/danog/AsyncOrm/Settings.md b/docs/docs/danog/AsyncOrm/Settings.md similarity index 100% rename from docs/danog/AsyncOrm/Settings.md rename to docs/docs/danog/AsyncOrm/Settings.md diff --git a/docs/danog/AsyncOrm/Settings/DriverSettings.md b/docs/docs/danog/AsyncOrm/Settings/DriverSettings.md similarity index 100% rename from docs/danog/AsyncOrm/Settings/DriverSettings.md rename to docs/docs/danog/AsyncOrm/Settings/DriverSettings.md diff --git a/docs/danog/AsyncOrm/Settings/MemorySettings.md b/docs/docs/danog/AsyncOrm/Settings/MemorySettings.md similarity index 100% rename from docs/danog/AsyncOrm/Settings/MemorySettings.md rename to docs/docs/danog/AsyncOrm/Settings/MemorySettings.md diff --git a/docs/danog/AsyncOrm/Settings/MysqlSettings.md b/docs/docs/danog/AsyncOrm/Settings/MysqlSettings.md similarity index 100% rename from docs/danog/AsyncOrm/Settings/MysqlSettings.md rename to docs/docs/danog/AsyncOrm/Settings/MysqlSettings.md diff --git a/docs/danog/AsyncOrm/Settings/PostgresSettings.md b/docs/docs/danog/AsyncOrm/Settings/PostgresSettings.md similarity index 100% rename from docs/danog/AsyncOrm/Settings/PostgresSettings.md rename to docs/docs/danog/AsyncOrm/Settings/PostgresSettings.md diff --git a/docs/danog/AsyncOrm/Settings/RedisSettings.md b/docs/docs/danog/AsyncOrm/Settings/RedisSettings.md similarity index 100% rename from docs/danog/AsyncOrm/Settings/RedisSettings.md rename to docs/docs/danog/AsyncOrm/Settings/RedisSettings.md diff --git a/docs/danog/AsyncOrm/Settings/SqlSettings.md b/docs/docs/danog/AsyncOrm/Settings/SqlSettings.md similarity index 100% rename from docs/danog/AsyncOrm/Settings/SqlSettings.md rename to docs/docs/danog/AsyncOrm/Settings/SqlSettings.md diff --git a/docs/danog/AsyncOrm/ValueType.md b/docs/docs/danog/AsyncOrm/ValueType.md similarity index 100% rename from docs/danog/AsyncOrm/ValueType.md rename to docs/docs/danog/AsyncOrm/ValueType.md diff --git a/docs/docs/index.md b/docs/docs/index.md new file mode 100644 index 0000000..29751af --- /dev/null +++ b/docs/docs/index.md @@ -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). \ No newline at end of file diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index 45e2fe8..0000000 --- a/docs/index.md +++ /dev/null @@ -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). \ No newline at end of file diff --git a/docs/index.md b/docs/index.md new file mode 120000 index 0000000..32d46ee --- /dev/null +++ b/docs/index.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/examples/2-automatic.php b/examples/1-automatic.php similarity index 54% rename from examples/2-automatic.php rename to examples/1-automatic.php index 8b8ce05..7ea5cbc 100644 --- a/examples/2-automatic.php +++ b/examples/1-automatic.php @@ -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 */ #[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 + */ + #[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(); diff --git a/examples/1-basic.php b/examples/2-manual.php similarity index 88% rename from examples/1-basic.php rename to examples/2-manual.php index acb95d5..57d03ae 100644 --- a/examples/1-basic.php +++ b/examples/2-manual.php @@ -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, diff --git a/src/DbArray.php b/src/DbArray.php index 4821238..11edd5a 100644 --- a/src/DbArray.php +++ b/src/DbArray.php @@ -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; } diff --git a/src/FieldConfig.php b/src/DbArrayBuilder.php similarity index 96% rename from src/FieldConfig.php rename to src/DbArrayBuilder.php index e84a289..b6b19e7 100644 --- a/src/FieldConfig.php +++ b/src/DbArrayBuilder.php @@ -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( /** diff --git a/src/DbAutoProperties.php b/src/DbAutoProperties.php index 2876a5d..6cfff5d 100644 --- a/src/DbAutoProperties.php +++ b/src/DbAutoProperties.php @@ -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 */ @@ -74,7 +78,7 @@ trait DbAutoProperties } } - $config = new FieldConfig( + $config = new DbArrayBuilder( $tablePrefix.($attr->tablePostfix ?? $property->getName()), $settings, $attr->keyType, diff --git a/src/DbObject.php b/src/DbObject.php index cbb1d9b..02d83e7 100644 --- a/src/DbObject.php +++ b/src/DbObject.php @@ -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 { } diff --git a/src/Driver/DriverArray.php b/src/Driver/DriverArray.php index 92f93d8..7c22043 100644 --- a/src/Driver/DriverArray.php +++ b/src/Driver/DriverArray.php @@ -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 $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 diff --git a/src/Driver/MemoryArray.php b/src/Driver/MemoryArray.php index 4fa5055..1cc1723 100644 --- a/src/Driver/MemoryArray.php +++ b/src/Driver/MemoryArray.php @@ -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; diff --git a/src/Driver/SqlArray.php b/src/Driver/SqlArray.php index d4e94f7..351f0e0 100644 --- a/src/Driver/SqlArray.php +++ b/src/Driver/SqlArray.php @@ -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 $serializer */ protected function __construct( - FieldConfig $config, + DbArrayBuilder $config, Serializer $serializer, protected readonly SqlConnectionPool $db, private readonly string $get, diff --git a/src/Internal/Containers/ObjectContainer.php b/src/Internal/Containers/ObjectContainer.php index 2c7c87e..ade6d2c 100644 --- a/src/Internal/Containers/ObjectContainer.php +++ b/src/Internal/Containers/ObjectContainer.php @@ -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 */ public DbArray $inner, - public FieldConfig $config, + public DbArrayBuilder $config, public int $cacheTtl, ) { $this->mutex = new LocalMutex; diff --git a/src/Internal/Driver/CachedArray.php b/src/Internal/Driver/CachedArray.php index 22a8a53..7afa05b 100644 --- a/src/Internal/Driver/CachedArray.php +++ b/src/Internal/Driver/CachedArray.php @@ -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(); diff --git a/src/Internal/Driver/MysqlArray.php b/src/Internal/Driver/MysqlArray.php index 41113b6..5985909 100644 --- a/src/Internal/Driver/MysqlArray.php +++ b/src/Internal/Driver/MysqlArray.php @@ -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 $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); diff --git a/src/Internal/Driver/ObjectArray.php b/src/Internal/Driver/ObjectArray.php index dcee416..4d74f55 100644 --- a/src/Internal/Driver/ObjectArray.php +++ b/src/Internal/Driver/ObjectArray.php @@ -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 $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); } diff --git a/src/Internal/Driver/PostgresArray.php b/src/Internal/Driver/PostgresArray.php index 5aa8378..0e4373b 100644 --- a/src/Internal/Driver/PostgresArray.php +++ b/src/Internal/Driver/PostgresArray.php @@ -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 $serializer */ - public function __construct(FieldConfig $config, Serializer $serializer) + public function __construct(DbArrayBuilder $config, Serializer $serializer) { self::$mutex ??= new LocalKeyedMutex; $settings = $config->settings; diff --git a/src/Internal/Driver/RedisArray.php b/src/Internal/Driver/RedisArray.php index 47e1203..5eccbc2 100644 --- a/src/Internal/Driver/RedisArray.php +++ b/src/Internal/Driver/RedisArray.php @@ -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 $serializer */ - public function __construct(FieldConfig $config, Serializer $serializer) + public function __construct(DbArrayBuilder $config, Serializer $serializer) { /** @var Serializer */ $serializer = match ($config->valueType) { diff --git a/tests/OrmTest.php b/tests/OrmTest.php index ba54bdb..d690336 100644 --- a/tests/OrmTest.php +++ b/tests/OrmTest.php @@ -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); diff --git a/tests/TestObject.php b/tests/TestObject.php index 384e249..8617cf9 100644 --- a/tests/TestObject.php +++ b/tests/TestObject.php @@ -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++;