Selection
class Selection implements Iterator, IRowContainer, ArrayAccess, Countable
Filtered table representation.
Selection is based on the great library NotORM http://www.notorm.com written by Jakub Vrana.
Properties
protected | $explorer | ||
protected | $context | back compatibility |
|
protected | $conventions | ||
protected | $cache | ||
protected | $sqlBuilder | ||
protected | $name | table name |
|
protected string|string[]|null | $primary | ||
protected | $primarySequence | primary column sequence name, false for autodetection |
|
protected ActiveRow[]|null | $rows | ||
protected ActiveRow[]|null | $data | ||
protected | $dataRefreshed | ||
protected | $globalRefCache | cache array of Selection and GroupedSelection prototypes |
|
protected | $refCache | ||
protected | $generalCacheKey | ||
protected | $specificCacheKey | ||
protected | $aggregation | of [conditions => [key => ActiveRow]]; used by GroupedSelection |
|
protected | $accessedColumns | ||
protected | $previousAccessedColumns | ||
protected | $observeCache | should instance observe accessed columns caching |
|
protected | $keys | of primary key values |
Methods
Creates filtered table representation.
No description
No description
No description
No description
No description
No description
No description
Loads cache of previous accessed columns and returns it.
No description
Returns row specified by primary key.
Fetches single row object.
Fetches all rows as associative array.
Fetches all rows.
Fetches all rows and returns associative tree.
Adds condition for primary key.
Adds where condition, more calls appends with AND.
Adds ON condition when joining specified table, more calls appends with AND.
Adds condition, more calls appends with AND.
Sets limit clause, more calls rewrite old values.
Sets offset using page number, more calls rewrite old values.
Aliases table. Example ':book:book_tag.tag', 'tg'
Executes aggregation function.
Counts number of rows. If column is not provided returns count of result rows, otherwise runs new sql counting query.
Returns minimum value from a column.
Returns maximum value from a column.
Returns sum of values in a column.
No description
No description
No description
No description
No description
Returns Selection parent for caching.
Loads refCache references
Returns general cache key independent on query parameters or sql limit Used e.g. for previously accessed columns caching
Returns object specific cache key dependent on query parameters Used e.g. for reference memory caching
No description
No description
Returns if selection requeried for more columns.
Inserts row in a table. Returns ActiveRow or number of affected rows for Selection or table without primary key.
Updates all rows in result set.
Deletes all rows in result set.
Returns referenced row.
Returns referencing rows.
No description
No description
No description
No description
No description
Returns specified row.
Tests if row exists.
Removes row from result set.
Details
at line 73
__construct(Explorer $explorer, Conventions $conventions, string $tableName, Storage|null $cacheStorage = null)
Creates filtered table representation.
at line 92
__destruct()
No description
at line 98
__clone()
No description
at line 104
string
getName()
No description
at line 113
string|array|null
getPrimary(bool $throw = true)
No description
at line 123
string|null
getPrimarySequence()
No description
at line 133
Selection
setPrimarySequence(string $sequence)
No description
at line 140
string
getSql()
No description
at line 150
array|bool
getPreviousAccessedColumns()
internal |
Loads cache of previous accessed columns and returns it.
at line 164
SqlBuilder
getSqlBuilder()
internal |
No description
at line 177
ActiveRow|null
get(mixed $key)
Returns row specified by primary key.
at line 188
ActiveRow|null
fetch()
Fetches single row object.
at line 201
mixed
fetchField(string|null $column = null)
deprecated
deprecated
Fetches single field.
at line 219
array
fetchPairs(string|int|Closure|null $keyOrCallback = null, string|int|null $value = null)
Fetches all rows as associative array.
at line 229
array
fetchAll()
Fetches all rows.
at line 238
array
fetchAssoc(string $path)
Fetches all rows and returns associative tree.
at line 252
Selection
select(string $columns, ...$params)
Adds select clause, more calls appends to the end.
at line 263
Selection
wherePrimary(mixed $key)
Adds condition for primary key.
at line 287
Selection
where(string|array $condition, ...$params)
Adds where condition, more calls appends with AND.
at line 299
Selection
joinWhere(string $tableChain, string $condition, ...$params)
Adds ON condition when joining specified table, more calls appends with AND.
at line 310
protected void
condition(string|array $condition, array $params, string|null $tableChain = null)
Adds condition, more calls appends with AND.
at line 335
Selection
whereOr(array $parameters)
Adds where condition using the OR operator between parameters.
More calls appends with AND.
at line 369
Selection
order(string $columns, ...$params)
Adds order clause, more calls appends to the end.
at line 380
Selection
limit(int|null $limit, int|null $offset = null)
Sets limit clause, more calls rewrite old values.
at line 391
Selection
page(int $page, int $itemsPerPage, $numOfPages = null)
Sets offset using page number, more calls rewrite old values.
at line 408
Selection
group(string $columns, ...$params)
Sets group clause, more calls rewrite old value.
at line 419
Selection
having(string $having, ...$params)
Sets having clause, more calls rewrite old value.
at line 430
Selection
alias(string $tableChain, string $alias)
Aliases table. Example ':book:book_tag.tag', 'tg'
at line 444
mixed
aggregation(string $function, string|null $groupFunction = null)
Executes aggregation function.
at line 465
int
count(string|null $column = null)
Counts number of rows. If column is not provided returns count of result rows, otherwise runs new sql counting query.
at line 479
mixed
min(string $column)
Returns minimum value from a column.
at line 488
mixed
max(string $column)
Returns maximum value from a column.
at line 497
mixed
sum(string $column)
Returns sum of values in a column.
at line 506
protected void
execute()
No description
at line 550
protected ActiveRow
createRow(array $row)
No description
at line 556
Selection
createSelectionInstance(string|null $table = null)
No description
at line 562
protected GroupedSelection
createGroupedSelectionInstance(string $table, string $column)
No description
at line 568
protected ResultSet
query(string $query)
No description
at line 574
protected void
emptyResultSet(bool $clearCache = true, bool $deleteReferencedCache = true)
No description
at line 596
protected void
saveCacheState()
No description
at line 624
protected Selection
getRefTable($refPath)
Returns Selection parent for caching.
at line 633
protected void
loadRefCache()
Loads refCache references
at line 642
protected string
getGeneralCacheKey()
Returns general cache key independent on query parameters or sql limit Used e.g. for previously accessed columns caching
at line 665
protected string
getSpecificCacheKey()
Returns object specific cache key dependent on query parameters Used e.g. for reference memory caching
at line 680
bool
accessColumn(string|null $key, bool $selectColumn = true)
internal |
No description
at line 746
void
removeAccessColumn(string $key)
internal |
No description
at line 757
bool
getDataRefreshed()
Returns if selection requeried for more columns.
at line 771
ActiveRow|array|int|bool
insert(iterable $data)
Inserts row in a table. Returns ActiveRow or number of affected rows for Selection or table without primary key.
at line 852
int
update(iterable $data)
Updates all rows in result set.
Joins in UPDATE are supported only in MySQL
at line 873
int
delete()
Deletes all rows in result set.
at line 886
ActiveRow|false|null
getReferencedTable(ActiveRow $row, string|null $table, string|null $column = null)
Returns referenced row.
at line 933
GroupedSelection|null
getReferencingTable(string $table, string|null $column = null, int|string|null $active = null)
Returns referencing rows.
at line 965
void
rewind()
No description
at line 974
ActiveRow|false
current()
No description
at line 982
string|int
key()
No description
at line 988
void
next()
No description
at line 996
bool
valid()
No description
at line 1010
void
offsetSet(string $key, ActiveRow $value)
Mimic row.
at line 1022
ActiveRow|null
offsetGet(string $key)
Returns specified row.
at line 1033
bool
offsetExists(string $key)
Tests if row exists.
at line 1044
void
offsetUnset(string $key)
Removes row from result set.