Download the PHP package autoprotect-group/php-dynamodb-odm without Composer
On this page you can find all versions of the php package autoprotect-group/php-dynamodb-odm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download autoprotect-group/php-dynamodb-odm
More information about autoprotect-group/php-dynamodb-odm
Files in autoprotect-group/php-dynamodb-odm
Package php-dynamodb-odm
Short Description PHP Object Document Mapper for AWS DynamoDB
License Apache-2.0
Informations about the package php-dynamodb-odm
AWS Dynamodb ODM for PHP
This is a library and an Object Document Mapper to use with AWS DynamoDB in a more convenient way.
Usage
Configure the ODM
Set up native client:
Set up the main operations lib client:
Set up the marshaller. Native AWS marshaller may be taken:
Set up the Query builder:
Set up annotation reader and annotation manager:
The hydrators for the models:
Serializer for inserting records into DB:
The full example is in here.
Model
Model field types
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:
BooleanType
: boolean for DynamoDb and for phpCollectionType
: list for DynamoDb, in php it's an array list of items of specific modelDateType
: string for DynamoDb, DateTime for phpEnumType
: string for DynamoDb, enum for phpFloatType
: number for DynamoDb, float for phpHashMapType
: map for DynamoDb, in php it's associative array of items of specific modelIntegerType
: number for DynamoDb, int for phpModelType
: map for DynamoDb, instance of model for phpMoney
: map for DynamoDb, special MoneyObject for PHP. Money value as a conceptNumberType
: number for DynamoDb. An abstract type, not a handy one. My be used occasionallyScalarCollectionType
: map for DynamoDb. in php it's associative array of any dynamodb compatible types excludingCollectionType
,HashMapType
orModelType
StringType
: string for DynamoDb and for php
Here is a model example:
Model full example is here: model.php
Enumerations example
Enumerations are also supported. Here is an example of the model with enumeration fields:
Fields encryption
Certain types custom encryption is supported. In case there are some fields which needs to be encrypted.
First of all we need to create a custom encryptor:
Then the decryptor should be passed into the hydrator:
And the model may be the following:
Set up the repository for your model
The best way to operate with records is to create a repository. There is a built-in already:
There are built-in operation in the default repository.
Get model by partition Id
Just by partition key
By partition key and sort key
Non-consistent read
Get one item
Insert model
Delete item
Document repository
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.
Setting DocumentRepository
up:
Get a model by projection expression
Get a specific scalar property by projection expression
Get/create/update/delete operations
Document repository supports specific property get/create/update/delete operations:
createDocument()
updateDocument()
removeDocument()
getDocumentCollection()
updateDocumentCollection()
createDocumentCollection()
Query builder
Another powerful feature is query builders. This adds flexibility to fetch items by specific criteria which is supported by DynamoDB.
This is a way to work with the Dynamodb using raw queries and results
Get query builder
Fetch items:
Update query builder
Ability to update specific attributes.
Local dev environment installation
-
In order to build a dev image, please, run:
- Then run to install dependencies:
Running tests
Unit tests
This package uses phpspec for running unit tests.
Run them using the following way:
One can use environment variables in the .env.local
file to be able to debug the library. For this just Copy file .env.local and set up the variable according to your OS.
And then run the tests with:
Functional tests
This package uses behat for running functional tests.
Then just run the tests:
Syntax check tests
You need to check if the code style is OK by running:
All versions of php-dynamodb-odm with dependencies
aws/aws-sdk-php Version ^3.218
doctrine/annotations Version ^1.13
adbario/php-dot-notation Version ^3.1
ext-bcmath Version *
moneyphp/money Version ^4.0