| Total Complexity | 9 |
| Total Lines | 90 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class ReadStatement extends \suda\database\statement\ReadStatement |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * 访问操作 |
||
| 12 | * |
||
| 13 | * @var TableAccess |
||
| 14 | */ |
||
| 15 | protected $access; |
||
| 16 | |||
| 17 | public function __construct(TableAccess $access) |
||
| 18 | { |
||
| 19 | $this->access = $access; |
||
| 20 | parent::__construct( |
||
| 21 | $access->getSource()->write()->rawTableName($access->getStruct()->getName()), |
||
| 22 | $access->getStruct(), |
||
| 23 | $access->getMiddleware() |
||
| 24 | ); |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * 取1 |
||
| 29 | * |
||
| 30 | * @param string|null $class |
||
| 31 | * @param array $args |
||
| 32 | * @return mixed |
||
| 33 | * @throws SQLException |
||
| 34 | */ |
||
| 35 | public function one(?string $class = null, array $args = []) |
||
| 36 | { |
||
| 37 | if ($this->isScroll() === false && $this->hasLimit() === false) { |
||
| 38 | $this->limit(0, 1); |
||
| 39 | } |
||
| 40 | return $this->access->run($this->wantOne($class, $args)); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @return bool |
||
| 45 | */ |
||
| 46 | private function hasLimit() |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * 取全部 |
||
| 53 | * |
||
| 54 | * @param string|null $class |
||
| 55 | * @param array $args |
||
| 56 | * @return array |
||
| 57 | * @throws SQLException |
||
| 58 | */ |
||
| 59 | public function all(?string $class = null, array $args = []): array |
||
| 60 | { |
||
| 61 | return $this->access->run($this->wantAll($class, $args)); |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * 取1 |
||
| 66 | * |
||
| 67 | * @param string|null $class |
||
| 68 | * @param array $args |
||
| 69 | * @return mixed |
||
| 70 | * @throws SQLException |
||
| 71 | */ |
||
| 72 | public function fetch(?string $class = null, array $args = []) |
||
| 73 | { |
||
| 74 | return $this->one($class, $args); |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * 取全部 |
||
| 79 | * |
||
| 80 | * @param string|null $class |
||
| 81 | * @param array $args |
||
| 82 | * @return array |
||
| 83 | * @throws SQLException |
||
| 84 | */ |
||
| 85 | public function fetchAll(?string $class = null, array $args = []): array |
||
| 86 | { |
||
| 87 | return $this->all($class, $args); |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Get 访问操作 |
||
| 92 | * |
||
| 93 | * @return TableAccess |
||
| 94 | */ |
||
| 95 | public function getAccess(): TableAccess |
||
| 98 | } |
||
| 99 | } |
||
| 100 |