/**
  * Initializes the DB connection component.
  * This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
  * @return void
  * @throws InvalidConfigException If [[db]] is invalid.
  */
 public function init()
 {
     parent::init();
     if (is_string($this->db)) {
         $this->db = Instance::ensure($this->db, Connection::className());
     }
 }
Esempio n. 2
0
 /**
  * Resolve the keys into `BatchGetItem` eligible argument.
  * @param string $table The name of the table.
  * @param array  $keys  The keys.
  * @return array
  */
 private function buildBatchKeyArgument($table, $keys)
 {
     $tableDescription = $this->db->createCommand()->describeTable($table)->execute();
     $keySchema = $tableDescription['Table']['KeySchema'];
     if (ArrayHelper::isIndexed($keys)) {
         $isScalar = is_string($keys[0]) || is_numeric($keys[0]);
         if ($isScalar) {
             return $this->buildBatchKeyArgumentFromIndexedArrayOfScalar($keySchema, $keys);
         } elseif (ArrayHelper::isIndexed($keys[0])) {
             return $this->buildBatchKeyArgumentFromIndexedArrayOfIndexedArray($keySchema, $keys);
         } else {
             return $this->buildBatchKeyArgumentFromIndexedArrayOfAssociativeArray($keySchema, $keys);
         }
     } else {
         return $this->buildBatchGetItemFromAssociativeArray($keySchema, $keys);
     }
 }
Esempio n. 3
0
 /**
  * @param string $table   The name of the Table.
  * @param array  $keys    The keys of the row.
  * @param array  $updates The hash attribute => value will be updated.
  * @param string $action  Action of the method, either 'PUT'|'ADD'|'DELETE'.
  * @param array  $options Additional options to the request argument.
  * @return static
  */
 public function updateItemSelectedAction($table, array $keys, array $updates, $action, array $options = [])
 {
     list($name, $query_argument) = $this->db->getQueryBuilder()->updateItemSelectedAction($table, $keys, $updates, $action, $options);
     return $this->setCommand($name, $query_argument);
 }
Esempio n. 4
0
 /**
  * @return DynamoDbClient
  */
 protected function getClient()
 {
     return $this->db->getClient();
 }
Esempio n. 5
0
 /**
  * Get multiple items from table using keys.
  *
  * @param string $table   The name of the table.
  * @param array  $keys    The keys of the row. This can be indexed array of
  * scalar value, indexed array of array of scalar value, indexed array of
  * associative array.
  * @param array  $options Additional options to the request argument.
  * @return static
  * @see QueryBuilder::batchGetItem
  */
 public function batchGetItem($table, array $keys, array $options = [])
 {
     list($name, $argument) = $this->db->getQueryBuilder()->batchGetItem($table, $keys, $options);
     return $this->setCommand($name, $argument);
 }