Skip to content

Commit 2aa58c8

Browse files
authored
docs: include base documentation (#2)
1 parent 0c58bb4 commit 2aa58c8

2 files changed

Lines changed: 151 additions & 0 deletions

File tree

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
DynamoPHP
2+
================
3+
![License](https://img.shields.io/github/license/edumarques/dynamophp)
4+
![Build Status](https://github.com/edumarques/dynamophp/actions/workflows/base.yml/badge.svg)
5+
![Coverage](https://codecov.io/gh/edumarques/dynamophp/graph/badge.svg?token=E20936W7JD)
6+
7+
---
8+
9+
**DynamoPHP** is a strongly-typed, attribute-based Object Data Mapper for Amazon DynamoDB. It is built on top of modern
10+
PHP, which enable definition of entities using PHP 8+ attributes and interaction with DynamoDB using a clean, expressive
11+
API.
12+
13+
Inspired by data mappers like [Doctrine](https://www.doctrine-project.org) and modeled after patterns in libraries such
14+
as [TypeDORM](https://github.com/typedorm/typedorm).
15+
16+
## Installation
17+
18+
```
19+
composer require edumarques/dynamophp
20+
```
21+
22+
## Documentation
23+
24+
Documentation is an ongoing effort. Our docs will continue to evolve as the project grows—contributions and
25+
improvements are welcome and encouraged!
26+
27+
- [Basic Usage Guide](docs/basic-guide.md)
28+
29+
## Contributing
30+
31+
Contributors are always welcome! For more information on how you can contribute, please read
32+
our [contribution guideline](CONTRIBUTING.md).
33+
34+
For any questions, feel free to reach out to me directly by email: [eduardomarqs1@gmail.com](mailto:eduardomarqs1@gmail.com).

docs/basic-guide.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Basic Usage Guide
2+
3+
**DynamoPHP** is a lightweight, attribute-based _Object Data Mapper_ designed to simplify development with Amazon
4+
DynamoDB. Inspired by modern data-mapping libraries, it brings a familiar, expressive API to PHP for modeling DynamoDB
5+
entities.
6+
7+
## Contents
8+
9+
- [Installation](#installation)
10+
- [Concepts](#concepts)
11+
- [Getting Started](#getting-started)
12+
13+
## Installation
14+
15+
Install **DynamoPHP** via Composer:
16+
17+
```bash
18+
composer require edumarques/dynamophp
19+
```
20+
21+
## Concepts
22+
23+
### Entity
24+
25+
An Entity in **DynamoPHP** is a PHP class that maps to a single item (also known as document or row) in a DynamoDB
26+
table. Entities are defined using PHP attributes.
27+
28+
### Attribute
29+
30+
An Attribute is an item's property (also known as field or column) that should be persisted in a DynamoDB table.
31+
Attributes are defined using PHP attributes.
32+
33+
### PartitionKey and SortKey
34+
35+
Compose the Primary Key of items, and reference how items are stored in and retrieved from the table. They are defined
36+
by fields in Entity's PHP attribute.
37+
38+
### Entity Manager
39+
40+
The Entity Manager is the main interface for performing operations like saving, fetching, querying, and deleting items
41+
from DynamoDB.
42+
43+
## Getting Started
44+
45+
To get started with **DynamoPHP**, you basically need to:
46+
47+
1. Define your entity model using attributes.
48+
2. Create an instance of the EntityManager.
49+
3. Use the entity manager to read/write data.
50+
51+
Here is an example of a simple entity:
52+
53+
```php
54+
use EduardoMarques\DynamoPHP\Attribute\Attribute;
55+
use EduardoMarques\DynamoPHP\Attribute\Entity;
56+
use EduardoMarques\DynamoPHP\Attribute\PartitionKey;
57+
use EduardoMarques\DynamoPHP\Attribute\SortKey;
58+
59+
#[Entity(
60+
table: 'users',
61+
partitionKey: new PartitionKey(['id']),
62+
sortKey: new SortKey(['createdAt'])
63+
)]
64+
class User
65+
{
66+
#[Attribute]
67+
public string $id;
68+
69+
#[Attribute(name: 'name')]
70+
public string $fullName;
71+
72+
#[Attribute]
73+
public DateTimeInterface $createdAt;
74+
}
75+
```
76+
77+
Each entity must:
78+
79+
- Declare a table name.
80+
- Define a partition key and, if the table schema requires, a sort key, via PartitionKey and SortKey objects in their
81+
respective fields.
82+
- Optionally, set persistent properties with #[Attribute].
83+
84+
Create an instance of EntityManager using the factory:
85+
86+
```php
87+
use EduardoMarques\DynamoPHP\ODM\EntityManagerFactory;
88+
89+
$entityManager = EntityManagerFactory::create([
90+
'region' => 'eu-central-1',
91+
'endpoint' => 'http://localhost:4566',
92+
'credentials' => ['key' => 'key', 'secret' => 'secret'],
93+
]);
94+
```
95+
96+
This internally creates a DynamoDB client using the AWS SDK and wires up all dependencies.
97+
98+
Run the operations you need, for instance:
99+
100+
```php
101+
// Create/update entity
102+
$user = new User();
103+
$user->id = 'user-123';
104+
$user->fullName = 'John Doe';
105+
$user->createdAt = new DateTime();
106+
107+
$entityManager->put($user);
108+
109+
// Fetch entity by primary key
110+
$entity = $entityManager->get(User::class, [
111+
'id' => 'user-123',
112+
'createdAt' => new DateTime(),
113+
]);
114+
```
115+
116+
That's it! The Entity Manager will handle all the wiring of dependencies and operations, including serialization and
117+
communication with the DynamoDB client.

0 commit comments

Comments
 (0)