Selection
class Selection implements IteratorAggregate, 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 | $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 |
Methods
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
Sets a row by primary key.
Returns specified row.
Tests if row exists.
Removes row from result set.
Details
at line 68
__construct(Explorer $explorer, string $tableName)
Creates filtered table representation.
at line 81
__destruct()
No description
at line 87
__clone()
No description
at line 93
string
getName()
No description
at line 103
string|array|null
getPrimary(bool $throw = true)
Returns table primary key.
at line 113
string|null
getPrimarySequence()
No description
at line 123
Selection
setPrimarySequence(string $sequence)
No description
at line 130
string
getSql()
No description
at line 141
array
getPreviousAccessedColumns()
| internal |
Loads cache of previous accessed columns and returns it.
at line 157
SqlBuilder
getSqlBuilder()
| internal |
No description
at line 163
Explorer
getExplorer()
No description
at line 176
ActiveRow|null
get(mixed $key)
Returns row specified by primary key.
at line 187
ActiveRow|null
fetch()
Returns the next row or null if there are no more rows.
at line 204
mixed
fetchField(string|null $column = null)
deprecated
deprecated
Fetches single field.
at line 226
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 236
array
fetchAll()
Returns all rows as an array indexed by primary key.
at line 247
array
fetchAssoc(string $path)
deprecated
deprecated
Returns all rows as associative tree.
at line 261
Selection
select(string $columns, mixed ...$params)
Adds select clause, more calls append to the end.
at line 272
Selection
wherePrimary(mixed $key)
Adds condition for primary key.
at line 301
Selection
where(string|array $condition, mixed ...$params)
Adds where condition, more calls append with AND.
at line 313
Selection
joinWhere(string $tableChain, string $condition, mixed ...$params)
Adds ON condition when joining specified table, more calls appends with AND.
at line 325
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 350
Selection
whereOr(array $parameters)
Adds where condition using the OR operator between parameters.
More calls appends with AND.
at line 384
Selection
order(string $columns, mixed ...$params)
Adds ORDER BY clause, more calls appends to the end.
at line 395
Selection
limit(int|null $limit, int|null $offset = null)
Sets LIMIT clause, more calls rewrite old values.
at line 406
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 423
Selection
group(string $columns, mixed ...$params)
Sets GROUP BY clause, more calls rewrite old value.
at line 434
Selection
having(string $having, mixed ...$params)
Sets HAVING clause, more calls rewrite old value.
at line 445
Selection
alias(string $tableChain, string $alias)
Aliases table. Example ':book:book_tag.tag', 'tg'
at line 459
mixed
aggregation(string $function, string|null $groupFunction = null)
Executes aggregation function.
at line 482
int
count(string|null $column = null)
Returns count of fetched rows, or runs COUNT($column) query when column is specified.
at line 496
mixed
min(string $column)
Returns minimum value from a column.
at line 505
mixed
max(string $column)
Returns maximum value from a column.
at line 514
mixed
sum(string $column)
Returns sum of values in a column.
at line 523
protected void
execute()
No description
at line 564
Selection
createSelectionInstance(string|null $table = null)
deprecated
deprecated
No description
at line 571
protected Result
query(string $query)
No description
at line 577
protected void
emptyResultSet(bool $clearCache = true, bool $deleteReferencedCache = true)
No description
at line 599
protected void
saveCacheState()
No description
at line 629
protected Selection
getRefTable(mixed $refPath)
Returns the root Selection used as the shared cache anchor for referenced rows.
at line 639
protected void
loadRefCache()
Initializes the reference cache for the current selection. Overridden by GroupedSelection.
at line 648
protected string
getGeneralCacheKey()
Returns general cache key independent of query parameters or SQL limit.
Used e.g. for previously accessed columns caching.
at line 671
protected string
getSpecificCacheKey()
Returns object-specific cache key dependent on query parameters.
Used e.g. for reference memory caching.
at line 686
bool
accessColumn(string|null $key, bool $selectColumn = true)
| internal |
No description
at line 752
void
removeAccessColumn(string $key)
| internal |
No description
at line 763
bool
getDataRefreshed()
Checks whether the selection re-queried for additional columns.
at line 778
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 859
int
update(iterable $data)
Updates all rows matching current conditions. JOINs in UPDATE are supported only by MySQL.
at line 877
int
delete()
Deletes all rows matching current conditions.
at line 892
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 944
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 982
Generator
getIterator()
No description
at line 1001
void
offsetSet(string|int $key, T $value)
Sets a row by primary key.
at line 1013
ActiveRow|null
offsetGet(string|int $key)
Returns specified row.
at line 1024
bool
offsetExists(string|int $key)
Tests if row exists.
at line 1035
void
offsetUnset(string|int $key)
Removes row from result set.