Selection
class Selection implements Iterator, IRowContainer, ArrayAccess, Countable
Represents filtered table result.
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 T[] | $rows | ||
| protected T[] | $data | ||
| protected | $dataRefreshed | ||
| protected | $globalRefCache | cache array of Selection and GroupedSelection prototypes |
|
| protected | $refCache | ||
| protected | $generalCacheKey | ||
| protected | $specificCacheKey | ||
| protected array<string,array<int|Row|ActiveRow>> | $aggregation | ||
| protected array<string,bool>|false|null | $accessedColumns | ||
| protected array<string,bool>|false|null | $previousAccessedColumns | ||
| protected | $observeCache | ||
| protected list<string|int> | $keys |
Methods
Creates filtered table representation.
No description
No description
No description
Returns table primary key.
No description
No description
No description
Loads cache of previous accessed columns and returns it.
No description
No description
Returns row specified by primary key.
Returns the next row or null if there are no more rows.
Returns all rows as associative array, where first argument specifies key column and second value column.
Returns all rows as an array indexed by primary key.
Adds select clause, more calls append to the end.
Adds condition for primary key.
Adds where condition, more calls append with AND.
Adds ON condition when joining specified table, more calls appends with AND.
Adds a WHERE or JOIN condition. When $tableChain is given, the condition is added to the JOIN ON clause.
Adds ORDER BY clause, more calls appends to the end.
Sets LIMIT clause, more calls rewrite old values.
Sets LIMIT and OFFSET for the given page number. Optionally calculates total number of pages.
Sets GROUP BY clause, more calls rewrite old value.
Sets HAVING clause, more calls rewrite old value.
Aliases table. Example ':book:book_tag.tag', 'tg'
Executes aggregation function.
Returns count of fetched rows, or runs COUNT($column) query when column is specified.
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
Returns the root Selection used as the shared cache anchor for referenced rows.
Initializes the reference cache for the current selection. Overridden by GroupedSelection.
Returns general cache key independent of query parameters or SQL limit.
Returns object-specific cache key dependent on query parameters.
No description
No description
Checks whether the selection re-queried for additional columns.
Inserts one or more rows into the table.
Updates all rows matching current conditions. JOINs in UPDATE are supported only by MySQL.
Deletes all rows matching current conditions.
Returns a referenced (parent) row for a belongs-to relationship.
Returns a grouped selection of referencing (child) rows for a has-many relationship.
No description
No description
No description
No description
No description
Sets a row by primary key.
Returns specified row.
Tests if row exists.
Removes row from result set.
Details
at line 76
__construct(Explorer $explorer, Conventions $conventions, string $tableName, Storage|null $cacheStorage = null)
Creates filtered table representation.
at line 95
__destruct()
No description
at line 101
__clone()
No description
at line 107
string
getName()
No description
at line 117
string|array|null
getPrimary(bool $throw = true)
Returns table primary key.
at line 127
string|null
getPrimarySequence()
No description
at line 137
Selection
setPrimarySequence(string $sequence)
No description
at line 144
string
getSql()
No description
at line 155
array
getPreviousAccessedColumns()
| internal |
Loads cache of previous accessed columns and returns it.
at line 171
SqlBuilder
getSqlBuilder()
| internal |
No description
at line 177
Explorer
getExplorer()
No description
at line 190
ActiveRow|null
get(mixed $key)
Returns row specified by primary key.
at line 201
ActiveRow|null
fetch()
Returns the next row or null if there are no more rows.
at line 218
mixed
fetchField(string|null $column = null)
deprecated
deprecated
Fetches single field.
at line 240
array
fetchPairs(string|int|Closure|null $keyOrCallback = null, string|int|null $value = null)
Returns all rows as associative array, where first argument specifies key column and second value column.
For duplicate keys, the last value is used. When using null as key, array is indexed from zero. Alternatively accepts callback returning value or key-value pairs.
at line 250
array
fetchAll()
Returns all rows as an array indexed by primary key.
at line 261
array
fetchAssoc(string $path)
deprecated
deprecated
Returns all rows as associative tree.
at line 275
Selection
select(string $columns, mixed ...$params)
Adds select clause, more calls append to the end.
at line 286
Selection
wherePrimary(mixed $key)
Adds condition for primary key.
at line 315
Selection
where(string|array $condition, mixed ...$params)
Adds where condition, more calls append with AND.
at line 327
Selection
joinWhere(string $tableChain, string $condition, mixed ...$params)
Adds ON condition when joining specified table, more calls appends with AND.
at line 339
protected void
condition(string|array $condition, array $params, string|null $tableChain = null)
Adds a WHERE or JOIN condition. When $tableChain is given, the condition is added to the JOIN ON clause.
at line 364
Selection
whereOr(array $parameters)
Adds where condition using the OR operator between parameters.
More calls appends with AND.
at line 398
Selection
order(string $columns, mixed ...$params)
Adds ORDER BY clause, more calls appends to the end.
at line 409
Selection
limit(int|null $limit, int|null $offset = null)
Sets LIMIT clause, more calls rewrite old values.
at line 420
Selection
page(int $page, int $itemsPerPage, int|null $numOfPages = null)
Sets LIMIT and OFFSET for the given page number. Optionally calculates total number of pages.
at line 437
Selection
group(string $columns, mixed ...$params)
Sets GROUP BY clause, more calls rewrite old value.
at line 448
Selection
having(string $having, mixed ...$params)
Sets HAVING clause, more calls rewrite old value.
at line 459
Selection
alias(string $tableChain, string $alias)
Aliases table. Example ':book:book_tag.tag', 'tg'
at line 473
mixed
aggregation(string $function, string|null $groupFunction = null)
Executes aggregation function.
at line 496
int
count(string|null $column = null)
Returns count of fetched rows, or runs COUNT($column) query when column is specified.
at line 510
mixed
min(string $column)
Returns minimum value from a column.
at line 519
mixed
max(string $column)
Returns maximum value from a column.
at line 528
mixed
sum(string $column)
Returns sum of values in a column.
at line 537
protected void
execute()
No description
at line 583
protected ActiveRow
createRow(array $row)
deprecated
deprecated
No description
at line 594
Selection
createSelectionInstance(string|null $table = null)
deprecated
deprecated
No description
at line 604
protected GroupedSelection
createGroupedSelectionInstance(string $table, string $column)
deprecated
deprecated
No description
at line 610
protected ResultSet
query(string $query)
No description
at line 616
protected void
emptyResultSet(bool $clearCache = true, bool $deleteReferencedCache = true)
No description
at line 638
protected void
saveCacheState()
No description
at line 668
protected Selection
getRefTable(mixed $refPath)
Returns the root Selection used as the shared cache anchor for referenced rows.
at line 678
protected void
loadRefCache()
Initializes the reference cache for the current selection. Overridden by GroupedSelection.
at line 687
protected string
getGeneralCacheKey()
Returns general cache key independent of query parameters or SQL limit.
Used e.g. for previously accessed columns caching.
at line 710
protected string
getSpecificCacheKey()
Returns object-specific cache key dependent on query parameters.
Used e.g. for reference memory caching.
at line 725
bool
accessColumn(string|null $key, bool $selectColumn = true)
| internal |
No description
at line 791
void
removeAccessColumn(string $key)
| internal |
No description
at line 802
bool
getDataRefreshed()
Checks whether the selection re-queried for additional columns.
at line 817
ActiveRow|array|int
insert(iterable $data)
Inserts one or more rows into the table.
Returns the inserted ActiveRow for single-row inserts, or the number of affected rows otherwise.
at line 902
int
update(iterable $data)
Updates all rows matching current conditions. JOINs in UPDATE are supported only by MySQL.
at line 923
int
delete()
Deletes all rows matching current conditions.
at line 938
ActiveRow|false|null
getReferencedTable(ActiveRow $row, string|null $table, string|null $column = null)
Returns a referenced (parent) row for a belongs-to relationship.
Returns null if the referenced row does not exist, false if the relationship is not defined.
at line 990
GroupedSelection|null
getReferencingTable(string $table, string|null $column = null, int|string|null $active = null)
Returns a grouped selection of referencing (child) rows for a has-many relationship.
at line 1027
void
rewind()
No description
at line 1036
ActiveRow|false
current()
No description
at line 1045
string|int
key()
No description
at line 1052
void
next()
No description
at line 1060
bool
valid()
No description
at line 1074
void
offsetSet(string|int $key, T $value)
Sets a row by primary key.
at line 1086
ActiveRow|null
offsetGet(string|int $key)
Returns specified row.
at line 1097
bool
offsetExists(string|int $key)
Tests if row exists.
at line 1108
void
offsetUnset(string|int $key)
Removes row from result set.