예제 #1
0
파일: Argument.php 프로젝트: phn-io/dal
 /**
  * {@inheritdoc}
  */
 public function toPg(MapperInterface $mapper, $provided, $argument = null)
 {
     if ($provided === false) {
         throw new LogicException('A value is required for this argument.');
     }
     return $mapper->toPg($argument, $this->type);
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function execute(FragmentInterface $query, Connection $connection, MapperInterface $mapper, $field = null, $type = null)
 {
     $result = $connection->executeFragment(new Node(['WITH set AS (', $query, ') SELECT to_json(set) AS json FROM set']));
     $value = pg_fetch_assoc($result);
     $value = json_decode($value['json'], true);
     pg_free_result($result);
     if ($field !== null) {
         $value = $value[$field];
     }
     if ($type !== null) {
         $value = $mapper->fromPg($value, $type);
     }
     return $value;
 }
예제 #3
0
 /**
  * @param MapperInterface $mapper
  * @param resource        $result
  * @param string          $field
  * @param string          $type
  *
  * @return \Generator
  */
 private function process(MapperInterface $mapper, $result, $field = null, $type = null)
 {
     while ($value = pg_fetch_assoc($result)) {
         $value = json_decode($value['json'], true);
         if ($field !== null) {
             $value = $value[$field];
         }
         if ($type !== null) {
             $value = $mapper->fromPg($value, $type);
         }
         (yield $value);
     }
     pg_free_result($result);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function query(FragmentInterface $query, Connection $connection, MapperInterface $mapper, $field = null, $type = null)
 {
     $result = $connection->executeFragment(new Node('SELECT to_json(set) AS json FROM (', $query, ') AS set'));
     while ($value = pg_fetch_assoc($result)) {
         $value = json_decode($value['json'], true);
         if ($field !== null) {
             $value = $value[$field];
         }
         if ($type !== null) {
             $value = $mapper->fromPg($value, $type);
         }
         (yield $value);
     }
     pg_free_result($result);
 }
예제 #5
0
 /**
  * @param MapperInterface $mapper
  * @param Connection      $connection
  * @param Node            $cursor
  * @param string          $field
  * @param string          $type
  *
  * @return \Generator
  */
 private function process(MapperInterface $mapper, Connection $connection, Node $cursor, $field = null, $type = null)
 {
     while ($result = $connection->executeFragment($cursor)) {
         if (pg_num_rows($result) === 0) {
             break;
         }
         while ($value = pg_fetch_assoc($result)) {
             $value = json_decode($value['json'], true);
             if ($field !== null) {
                 $value = $value[$field];
             }
             if ($type !== null) {
                 $value = $mapper->fromPg($value, $type);
             }
             (yield $value);
         }
         pg_free_result($result);
     }
     pg_free_result($result);
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function query(FragmentInterface $query, Connection $connection, MapperInterface $mapper, $field = null, $type = null)
 {
     $cursor = self::next();
     $query = new Node('DECLARE ', $cursor, ' CURSOR FOR (SELECT to_json(set) AS json FROM (', $query, ') AS set)');
     $connection->executeFragment($query);
     while ($result = $connection->executeFragment(new Node('FETCH 10 FROM ', $cursor))) {
         if (pg_num_rows($result) === 0) {
             break;
         }
         while ($value = pg_fetch_assoc($result)) {
             $value = json_decode($value['json'], true);
             if ($field !== null) {
                 $value = $value[$field];
             }
             if ($type !== null) {
                 $value = $mapper->fromPg($value, $type);
             }
             (yield $value);
         }
         pg_free_result($result);
     }
     pg_free_result($result);
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function toPg(MapperInterface $mapper, $provided, $argument = null)
 {
     return $mapper->toPg($provided === true ? $argument : $this->default, $this->type);
 }