File tree Expand file tree Collapse file tree 3 files changed +71
-0
lines changed
Expand file tree Collapse file tree 3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 2323use AsyncAws \DynamoDb \Result \PutItemOutput ;
2424use AsyncAws \DynamoDb \Result \QueryOutput ;
2525use AsyncAws \DynamoDb \Result \ScanOutput ;
26+ use AsyncAws \DynamoDb \Result \TableExistsWaiter ;
2627use AsyncAws \DynamoDb \Result \UpdateItemOutput ;
2728use AsyncAws \DynamoDb \Result \UpdateTableOutput ;
2829
@@ -255,6 +256,23 @@ public function scan($input): ScanOutput
255256 return new ScanOutput ($ response , $ this , $ input );
256257 }
257258
259+ /**
260+ * Check status of operation describeTable.
261+ *
262+ * @see describeTable
263+ *
264+ * @param array{
265+ * TableName: string,
266+ * }|DescribeTableInput $input
267+ */
268+ public function tableExists ($ input ): TableExistsWaiter
269+ {
270+ $ input = DescribeTableInput::create ($ input );
271+ $ response = $ this ->getResponse ($ input ->request ());
272+
273+ return new TableExistsWaiter ($ response , $ this , $ input );
274+ }
275+
258276 /**
259277 * Edits an existing item's attributes, or adds a new item to the table if it does not already exist. You can put,
260278 * delete, or add attribute values. You can also perform a conditional update on an existing item (insert a new
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace AsyncAws \DynamoDb \Result ;
4+
5+ use AsyncAws \Core \Exception \Http \HttpException ;
6+ use AsyncAws \Core \Response ;
7+ use AsyncAws \Core \Waiter ;
8+ use AsyncAws \DynamoDb \DynamoDbClient ;
9+ use AsyncAws \DynamoDb \Input \DescribeTableInput ;
10+
11+ class TableExistsWaiter extends Waiter
12+ {
13+ protected const WAIT_TIMEOUT = 500.0 ;
14+ protected const WAIT_DELAY = 20.0 ;
15+
16+ protected function extractState (Response $ response , ?HttpException $ exception ): string
17+ {
18+ if (200 === $ response ->getStatusCode () && 'ACTIVE ' === ($ response ->toArray ()['Table ' ]['TableStatus ' ] ?? null )) {
19+ return self ::STATE_SUCCESS ;
20+ }
21+
22+ if (null !== $ exception ) {
23+ return self ::STATE_PENDING ;
24+ }
25+
26+ /** @psalm-suppress TypeDoesNotContainType */
27+ return null === $ exception ? self ::STATE_PENDING : self ::STATE_FAILURE ;
28+ }
29+
30+ protected function refreshState (): Waiter
31+ {
32+ if (!$ this ->awsClient instanceof DynamoDbClient) {
33+ throw new \InvalidArgumentException ('missing client injected in waiter result ' );
34+ }
35+ if (!$ this ->input instanceof DescribeTableInput) {
36+ throw new \InvalidArgumentException ('missing last request injected in waiter result ' );
37+ }
38+
39+ return $ this ->awsClient ->TableExists ($ this ->input );
40+ }
41+ }
Original file line number Diff line number Diff line change @@ -277,6 +277,18 @@ public function testUpdateTable(): void
277277 self ::assertEquals (8 , $ result ->getTableDescription ()->getProvisionedThroughput ()->getWriteCapacityUnits ());
278278 }
279279
280+ public function testTableExists (): void
281+ {
282+ $ client = $ this ->getClient ();
283+
284+ $ input = new DescribeTableInput ([
285+ 'TableName ' => $ this ->tableName ,
286+ ]);
287+
288+ self ::assertTrue ($ client ->tableExists ($ input )->isSuccess ());
289+ self ::assertFalse ($ client ->tableExists (['TableName ' => 'does-not-exists ' ])->isSuccess ());
290+ }
291+
280292 private function getClient (): DynamoDbClient
281293 {
282294 if ($ this ->client instanceof DynamoDbClient) {
You can’t perform that action at this time.
0 commit comments