matthieuwerner / dynamodb-storable
This component, based on the Symfony serializer and async-aws, is a human-readable andquick abstraction to easily store serialized objects in DynamoDB.
Fund package maintenance!
matthieuwerner
www.paypal.me/matthieuwernerfr
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Type:project
Requires
- php: >=8.0
- async-aws/dynamo-db: ^1.2
- symfony/property-access: ^5.0|^6.0
- symfony/serializer: ^5.0|^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- phpstan/phpstan: ^1.7
- phpunit/phpunit: ^9.5
README
DynamoDB Storable
This component, based on the Symfony serializer and async-aws, is a human-readable and quick abstraction to easily store serialized objects in DynamoDB 🚀.
This storage use an existing DynamoDB table and create entries with
the following structure :
{"key", "namespace", "value", "class", "date""}
.
Installation
composer require matthieuwerner/dynamodb-storable
Usage
Adding service
Option 1: auto wiring (Symfony/Laravel)
use Storable\Storage; protected function anyAction(Storage $storage): string { $storage->set('key', 'value'); // ... }
Option 2: instantiate class
use Storable\Storage; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer; protected function anyAction(): string { $encoders = [new JsonEncoder()]; $normalizers = [new ObjectNormalizer()]; $storage = new Storage($dynamoDbClientMock, new Serializer($normalizers, $encoders)); $storage->set('key', 'value'); // ... }
Write
// String $storage->set('key', 'value'); // Object $myObject = new MyObject(); $storage->setObject($myObject);
/!\ Working with objects need that they implement "StorableInterface"
Read
// String $storage->get('key'); // Return a string // Object $storage->get($objectId); // Return an object
Remove
$storage->remove('key');
Working with namespaces
// Get all objects in a namespace $storage->getByNamespace('namespace'); // Remove all objects in a namespace $storage->removeNamespace('namespace');
Changing default values
// Change the default table name (default is "storage") $storage->setTable('newTableName'); // Change the default namespace (default is "main") $storage->setNamespace('newNamespaceName'); // Change the default attribute "key" in the table structure $storage->setAttributeKey('newKeyAttribute'); // Change the default attribute "namespace" in the table structure $storage->setAttributeNamespace('newNamespaceAttribute'); // Change the default attribute "value" in the table structure $storage->setAttributeValue('newValueAttribute'); // Change the default attribute "class" in the table structure $storage->setAttributeClass('newClassAttribute'); // Change the default attribute "date" in the table structure $storage->setAttributeDate('newDateAttribute');