You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+334-1Lines changed: 334 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,340 @@ This is a library and an Object Document Mapper to use with AWS DynamoDB in a mo
6
6
7
7
## Usage
8
8
9
-
To be added soon...
9
+
### Configure the ODM
10
+
11
+
Set up native client:
12
+
13
+
```php
14
+
$dynamoDbClient = new DynamoDbClient(array_merge(
15
+
[
16
+
'region' => 'eu-west-2',
17
+
'version' => 'latest',
18
+
]
19
+
));
20
+
```
21
+
22
+
Set up the main operations lib client:
23
+
24
+
```php
25
+
$client = new DynamodbOperationsClient($dynamoDbClient);
26
+
```
27
+
28
+
Set up the marshaller. Native AWS marshaller may be taken:
29
+
```php
30
+
$marshaler = new Marshaler();
31
+
```
32
+
Set up the Query builder:
33
+
34
+
```php
35
+
$queryBuilder = new QueryBuilder($marshaler, new ExpressionFactory($marshaler));
36
+
```
37
+
38
+
Set up annotation reader and annotation manager:
39
+
40
+
```php
41
+
// annotation reader
42
+
$annotationReader = new AnnotationReader();
43
+
44
+
// annotation manager
45
+
$annotationManager = new AnnotationManager($annotationReader);
46
+
```
47
+
48
+
The hydrators for the models:
49
+
50
+
```php
51
+
$newModelHydrator = new Hydrator(NewModel::class, $annotationManager);
52
+
$sortKeyModelHydrator = new Hydrator(SortKeyModel::class, $annotationManager);
53
+
```
54
+
Serializer for inserting records into DB:
55
+
56
+
```php
57
+
// serializer for
58
+
$serializer = new Serializer($annotationManager);
59
+
```
60
+
61
+
The full example is in [here](examples/initialise_client.php).
62
+
63
+
### Model
64
+
65
+
#### Model field types
66
+
67
+
The lib operates with models. Each model may have various supported field types. Here is a list of types which correlate with PHP and Dynamodb types:
68
+
69
+
-`BooleanType`: boolean for DynamoDb and for php
70
+
-`CollectionType`: list for DynamoDb, in php it's an array list of items of specific model
71
+
-`DateType`: string for DynamoDb, DateTime for php
72
+
-`EnumType`: string for DynamoDb, enum for php
73
+
-`FloatType`: number for DynamoDb, float for php
74
+
-`HashMapType`: map for DynamoDb, in php it's associative array of items of specific model
75
+
-`IntegerType`: number for DynamoDb, int for php
76
+
-`ModelType`: map for DynamoDb, instance of model for php
77
+
-`Money`: map for DynamoDb, special MoneyObject for PHP. [Money value](https://martinfowler.com/eaaCatalog/money.html) as a concept
78
+
-`NumberType`: number for DynamoDb. An abstract type, not a handy one. My be used occasionally
79
+
-`ScalarCollectionType`: map for DynamoDb. in php it's associative array of any dynamodb compatible types excluding `CollectionType`, `HashMapType` or `ModelType`
80
+
-`StringType`: string for DynamoDb and for php
81
+
82
+
Here is a model example:
83
+
84
+
```php
85
+
class ExampleDemoModel extends Model
86
+
{
87
+
protected const TABLE_NAME = 'test-table';
88
+
89
+
// Primary means that this is a partition key for the DynamoDb table
Sometimes we need to fetch not the whole model, but just a part of it. For this purpose there is such called `DocumentRepository`. The part of the document may be technically fetched using native DynamoDb projection expressions.
0 commit comments