chrisjenkinson/dynamo-db-read-model
Composer 安装命令:
composer require chrisjenkinson/dynamo-db-read-model
包简介
A DynamoDB ReadModel implementation for Broadway.
README 文档
README
A DynamoDB-backed Broadway read model repository.
Installation
composer require chrisjenkinson/dynamo-db-read-model
The package supports async-aws/dynamo-db ^1.3, ^2.0, and ^3.0.
DynamoDB Table
Create one table for the read model store. The table uses a composite primary key:
| Attribute | Type | Key | Description |
|---|---|---|---|
Name |
String | Partition | Repository name passed to RepositoryFactory::create() |
Id |
String | Sort | Read model identifier from Identifiable::getId() |
Data |
String | - | JSON-encoded serialized read model payload |
The library queries by Name to load all read models for a repository, and uses
Name + Id for single-item reads, writes, and deletes. It does not require
secondary indexes.
find($id) uses the full primary key (Name + Id) and is the bounded lookup
to prefer for production read paths. findAll() queries the full repository
partition for the configured Name and returns every read model in memory.
findBy() also queries the full repository partition, deserializes each read
model, and then filters in PHP. For production-sized collections, avoid using
findAll() or findBy() on request paths unless that full-partition work is
intentional.
Snapshot Store
This release changes the public constructors for DynamoDbRepositoryFactory
and DynamoDbRepository.
DynamoDbRepositoryFactory requires a ReadModelSnapshotStore so repositories
created by the same factory can suppress unchanged physical writes without an
extra DynamoDB read:
$factory = new DynamoDbRepositoryFactory($client, $serializer, 'read-models', new ReadModelSnapshotStore());
Direct DynamoDbRepository construction also needs the same dependency:
$repository = new DynamoDbRepository( $client, $inputBuilder, $serializer, $jsonEncoder, $jsonDecoder, 'read-models', 'repository-name', MyReadModel::class, new ReadModelSnapshotStore() );
Call $factory->clearSnapshots() before reusing the same factory after deleting
or recreating the backing read-model table.
Example AWS CLI setup:
aws dynamodb create-table \
--table-name read-models \
--billing-mode PAY_PER_REQUEST \
--attribute-definitions \
AttributeName=Name,AttributeType=S \
AttributeName=Id,AttributeType=S \
--key-schema \
AttributeName=Name,KeyType=HASH \
AttributeName=Id,KeyType=RANGE
Testing
The test suite expects DynamoDB Local. In GitHub Actions this is provided as a
service named dynamodb-local; locally, override the endpoint:
DYNAMODB_ENDPOINT=http://127.0.0.1:8000 \ AWS_ACCESS_KEY_ID=none \ AWS_SECRET_ACCESS_KEY=none \ composer run-script phpunit
CI tests supported PHP versions against each supported AsyncAws DynamoDB major.
Quality Checks
vendor/bin/ecs check --config ecs.php composer run-script phpstan composer run-script infection
统计信息
- 总下载量: 4.29k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2022-09-24