1. Go to this page and download the library: Download aiotu/terseq 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/ */
aiotu / terseq example snippets
$client = new \Aws\DynamoDb\DynamoDbClient([
'region' => 'us-west-2',
'version' => 'latest',
]);
$manager = new \Terseq\DatabaseManager($client, new Marshaler());
use Terseq\Builders\Table;
class Books extends Table
{
public function getTableName(): string
{
return 'Books';
}
public function getKeys(): Keys
{
return new Keys(partitionKey: 'BookId', sortKey: null);
}
}
use Terseq\Builders\Table;
class BooksTable extends Table
{
/**
* Table name
*/
public function getTableName(): string
{
return 'Books';
}
/**
* Partition key and sort key (optional)
*/
public function getKeys(): Keys
{
return new Keys(partitionKey: 'BookId', sortKey: 'ReleaseDate');
}
/**
* Secondary index map (optional) also known as GSI and LSI
*/
public function getSecondaryIndexMap(): ?array
{
return [
'AuthorIndex' => new Keys(partitionKey: 'AuthorId', sortKey: 'AuthorBornYear'),
'GenreIndex' => new Keys(partitionKey: 'GenreId', sortKey: 'GenreName'),
'LsiExample' => new Keys(partitionKey: 'BookId', sortKey: 'AuthorBornYear'),
];
}
}
$manager = new \Terseq\DatabaseManager(
client: $client,
marshaler: new Marshaler(),
singleTable: new class extends \Terseq\Builders\Table {
public function getTableName(): string
{
return 'Books';
}
public function getKeys(): Keys
{
return new Keys(partitionKey: 'BookId');
}
},
);