Beispiel #1
0
 protected function createCustomersRangeTable()
 {
     $command = $this->createCommand();
     /* @var $command \UrbanIndo\Yii2\DynamoDb\Command */
     $table = \test\data\CustomerRange::tableName();
     if ($command->tableExists($table)) {
         $command->deleteTable($table)->execute();
     }
     $index = \test\data\CustomerRange::secondaryIndex()[0];
     $command->createTable($table, ['AttributeDefinitions' => [['AttributeName' => \test\data\CustomerRange::primaryKey()[0], 'AttributeType' => 'N'], ['AttributeName' => \test\data\CustomerRange::primaryKey()[1], 'AttributeType' => 'S'], ['AttributeName' => \test\data\CustomerRange::keySecondayIndex()[$index][1], 'AttributeType' => 'S']], 'KeySchema' => [['AttributeName' => \test\data\CustomerRange::primaryKey()[0], 'KeyType' => 'HASH'], ['AttributeName' => \test\data\CustomerRange::primaryKey()[1], 'KeyType' => 'RANGE']], 'LocalSecondaryIndexes' => [['IndexName' => $index, 'KeySchema' => [['AttributeName' => \test\data\CustomerRange::keySecondayIndex()[$index][0], 'KeyType' => 'HASH'], ['AttributeName' => \test\data\CustomerRange::keySecondayIndex()[$index][1], 'KeyType' => 'RANGE']], 'Projection' => ['ProjectionType' => 'ALL']]], 'ProvisionedThroughput' => ['ReadCapacityUnits' => 10, 'WriteCapacityUnits' => 10]])->execute();
 }
 /**
  * Test build Query method with complicated condition
  * @return void
  */
 public function testBuildQueryWithComplicatedCondition()
 {
     $qb = $this->createQueryBuilder();
     $faker = \Faker\Factory::create();
     $name = $faker->firstNameFemale;
     $id1 = $faker->firstNameFemale;
     $id2 = $faker->firstNameFemale;
     $query1 = $this->createQuery()->select(['id', 'name', 'contacts'])->where(['name' => $name])->andWhere(['id' => $id1]);
     $query2 = $this->createQuery()->select(['id', 'name', 'contacts'])->where(['name' => $name])->andWhere(['id' => [$id1, $id2]]);
     $query3 = $this->createQuery()->select(['id', 'name', 'contacts'])->where(['name' => $name])->andWhere(['attribute_exists', 'id']);
     $query4 = $this->createQuery()->select(['id', 'name', 'contacts'])->where(['name' => $name])->andWhere(['begins_with', 'id', $id1]);
     $expected = ['TableName' => Customer::tableName(), 'KeyConditionExpression' => '(name=:dqp0) AND (id=:dqp1)', 'ProjectionExpression' => 'id, name, contacts', 'ExpressionAttributeValues' => [':dqp0' => ['S' => $name], ':dqp1' => ['S' => $id1]]];
     $this->assertEquals($expected, $qb->build($query1)[1]);
     $expected['KeyConditionExpression'] = '(name=:dqp0) AND (id IN (:dqp1, :dqp2))';
     $expected['ExpressionAttributeValues'][':dqp2'] = ['S' => $id2];
     $this->assertEquals($expected, $qb->build($query2)[1]);
     $expected['KeyConditionExpression'] = '(name=:dqp0) AND (attribute_exists (:dqp1))';
     $expected['ExpressionAttributeValues'][':dqp1'] = ['S' => 'id'];
     unset($expected['ExpressionAttributeValues'][':dqp2']);
     $this->assertEquals($expected, $qb->build($query3)[1]);
     $expected['KeyConditionExpression'] = '(name=:dqp0) AND (begins_with (id, :dqp1))';
     $expected['ExpressionAttributeValues'][':dqp1'] = ['S' => $id1];
     $this->assertEquals($expected, $qb->build($query4)[1]);
 }