PHP code example of justraviga / laravel-dynamodb-extreme
1. Go to this page and download the library: Download justraviga/laravel-dynamodb-extreme library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
justraviga / laravel-dynamodb-extreme example snippets
class Model extends \DynamoDb\Models\DynamoDbModel
{
// optional, see environment variable for table name
protected string $table = 'models';
// optional, see environment variable for partition/sort keys
protected string $partitionKey = 'pk';
protected string $sortKey = 'sk';
//
class Model extends \DynamoDb\Models\DynamoDbModel
{
// optional
protected array $fieldMappings = [
'pk' => 'my_uuid',
'sk' => 'created_date',
];
}
class Model extends \DynamoDb\Models\DynamoDbModel { }
$model = new Model();
// partition key = 'MODEL#{uuid-7}
// sort key = 'MODEL'
class Model extends \DynamoDb\Models\DynamoDbModel
{
public function defaultPartitionKey(): string
{
return 'MODEL#' . random_int(0,1000);
}
public function defaultSortKey(): string
{
return 'CREATED_AT#' . now()->toISOString();
}
public function defaultValues(): array
{
return [
'attribute' => 'default value',
];
}
}
class ParentModel extends \DynamoDb\Models\DynamoDbModel
{
public function childModels(): \DynamoDb\DynamoDb\Relation
{
return $this->addRelation(ChildModel::class);
}
}
class ChildModel extends \DynamoDb\Models\DynamoDbModel
{
public static function relationSearchParams(): array
{
return [
'sk',
'begins_with',
'CLASSNAME#'
];
}
}
class Model extends \DynamoDb\Models\DynamoDbModel
{
public function children(): \DynamoDb\DynamoDb\Relation
{
return $this->addRelation(Child::class);
}
}
$model = Model::find(...);
$model->children->map(fn ($child) => $child->doSomething());
class Model extends \DynamoDb\Models\DynamoDbModel
{
public function inline(): InlineRelation
{
return $this->addInlineRelation(Inline::class, 'inline');
}
}
$model = Model::find(...);
$model->inline->map(fn ($child) => $child->doSomething());
class Model extends \DynamoDb\Models\DynamoDbModel
{
// optional, see config values
protected array $indexes = [
'gsi1' => [
'pk' => 'gsi1_pk',
'sk' => 'gsi1_sk',
],
];
//
class Model extends \JustRaviga\LaravelDynamodbExtreme\Models\DynamoDbModel
{
// optional
protected array $fieldMappings = [
'gsi1_pk' => 'user_uuid',
'gsi1_sk' => 'created_date',
];
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.