Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Apr 6, 2024
1 parent 9a5641d commit be9b7e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
36 changes: 6 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion examples/2-manual.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@
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

0 comments on commit be9b7e1

Please sign in to comment.