From be9b7e10398da6ade90d8d6bde532e8ba1fbdb43 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 6 Apr 2024 13:13:50 +0200 Subject: [PATCH] Improve documentation --- README.md | 36 ++++++------------------------------ examples/2-manual.php | 7 ++++++- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 7d97e4f..dc07279 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,11 @@ There are two main ways to use the ORM: through automatic ORM properties, which * [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 of the specified type, from the specified database. +The `DbArray` obtained through one of the methods above 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). ### Settings @@ -79,35 +83,7 @@ For optimal performance, the specified types must be as strict as possible, here 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. - -```php -$fieldConfig = new DbArrayBuilder( - 'tableName', - $settings, - KeyType::STRING, - ValueType::OBJECT -); - -$db = $fieldConfig->build(); - -class MyObject extends DbObject -{ - public function __construct( - public readonly string $value - ) { - } -} - -$db->set("a", new MyObject('v')); -$obj = $db->get("a"); - -var_dump($obj->value); -$obj->value = 'newValue'; -$obj->save(); - -var_dump($db->get("a")->value); // newValue -``` +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](https://github.com/danog/AsyncOrm/blob/master/examples/2-manual.php). ## API Documentation diff --git a/examples/2-manual.php b/examples/2-manual.php index c85d9d0..fe08619 100644 --- a/examples/2-manual.php +++ b/examples/2-manual.php @@ -50,11 +50,16 @@ $db = $fieldConfig->build(); class MyObject extends DbObject { public function __construct( - public readonly string $value + public string $value ) { } } $db->set("a", new MyObject('v')); $obj = $db->get("a"); + var_dump($obj->value); +$obj->value = 'newValue'; +$obj->save(); + +var_dump($db->get("a")->value); // newValue