Skip to content

Commit 6fc5caf

Browse files
committed
Added listing method to database storage and readable storage interface.
1 parent afa4f31 commit 6fc5caf

2 files changed

Lines changed: 39 additions & 8 deletions

File tree

src/Darya/Database/Storage.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,35 @@ protected function prepareUpdate($table, $data, $where = null, $limit = null) {
253253
}
254254

255255
/**
256-
* Retrieve the distinct values of the given resource field.
256+
* Retrieve the distinct values of the given database column.
257257
*
258258
* @param string $table
259-
* @param string $field
260-
* @param array $filter [optional]
261-
* @param array $order [optional]
262-
* @param int $limit [optional]
263-
* @param int $offset [optional]
259+
* @param string $column
260+
* @param array $filter [optional]
261+
* @param array $order [optional]
262+
* @param int $limit [optional]
263+
* @param int $offset [optional]
264+
* @return array
265+
*/
266+
public function distinct($table, $column, array $filter = array(), $order = array(), $limit = null, $offset = 0) {
267+
$query = $this->prepareSelect($table, "DISTINCT $column", $this->prepareWhere($filter), $this->prepareOrderBy($order), $this->prepareLimit($limit, $offset));
268+
269+
return $this->connection->query($query)->data;
270+
}
271+
272+
/**
273+
* Retrieve all values of the given database column.
274+
*
275+
* @param string $table
276+
* @param string $column
277+
* @param array $filter [optional]
278+
* @param array $order [optional]
279+
* @param int $limit [optional]
280+
* @param int $offset [optional]
281+
* @return array
264282
*/
265-
public function distinct($table, $field, array $filter = array(), $order = array(), $limit = null, $offset = 0) {
266-
$query = $this->prepareSelect($table, "DISTINCT $field", $this->prepareWhere($filter), $this->prepareOrderBy($order), $this->prepareLimit($limit, $offset));
283+
public function listing($table, $column, array $filter = array(), $order = array(), $limit = null, $offset = 0) {
284+
$query = $this->prepareSelect($table, "$column", $this->prepareWhere($filter), $this->prepareOrderBy($order), $this->prepareLimit($limit, $offset));
267285

268286
return $this->connection->query($query)->data;
269287
}

src/Darya/Storage/Readable.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ interface Readable {
2020
*/
2121
public function read($resource, array $filter = array(), $order = null, $limit = null, $offset = 0);
2222

23+
/**
24+
* Retrieve all values of the given resource field.
25+
*
26+
* @param string $resource
27+
* @param string $field
28+
* @param array $filter [optional]
29+
* @param array $order [optional]
30+
* @param int $limit [optional]
31+
* @param int $offset [optional]
32+
* @return array
33+
*/
34+
public function listing($resource, $field, array $filter = array(), $order = array(), $limit = null, $offset = 0);
35+
2336
/**
2437
* Count the given resource using the given filter.
2538
*

0 commit comments

Comments
 (0)