Query
class Query extends Query
ORM query builder.
Properties
protected Connection | $connection | Database connection. | from Query |
protected HelperInterface | $helper | Query helper. | from Query |
protected Compiler | $compiler | Query compiler. | from Query |
protected mixed | $table | Database table. | from Query |
protected bool | $distinct | Select distinct? | from Query |
protected array | $commonTableExpressions | Common table expressions. | from Query |
protected array | $setOperations | Set operations. | from Query |
protected array | $columns | Columns from which we are fetching data. | from Query |
protected array | $wheres | WHERE clauses. | from Query |
protected array | $joins | JOIN clauses. | from Query |
protected array | $groupings | GROUP BY clauses. | from Query |
protected array | $havings | HAVING clauses. | from Query |
protected array | $orderings | ORDER BY clauses. | from Query |
protected int|null | $limit | Limit. | from Query |
protected int|null | $offset | Offset. | from Query |
protected bool|string|null | $lock | Lock. | from Query |
protected string|null | $prefix | Prefix. | from Query |
protected bool | $inSubqueryContext | Is the query in subquery context? | from Query |
static protected Closure|PaginationFactoryInterface | $paginationFactory | Pagination factory. | from Query |
protected ORM | $model | Instance of the model to hydrate. | |
protected string | $modelClass | Class name of the model we're hydrating. | |
protected array | $relationCounters | Relation count subqueries. |
Methods
Create a fresh compiler instance and clone set operation queries when we clone the query.
Returns the columns from which we are fetching data.
Executes the closure if the compiler is of the correct class.
Adds a recursive common table expression.
Sets the columns we want to select using raw SQL.
Adds a WHERE clause.
Adds a raw WHERE clause.
Adds a OR WHERE clause.
Adds a raw OR WHERE clause.
Adds a date comparison clause.
Adds a date comparison clause.
Adds a column comparison clause.
Adds a column comparison clause.
Adds a BETWEEN clause.
Adds a OR NOT BETWEEN clause.
Adds a date range clause.
Adds a date range clause.
Adds a date range clause.
Adds a date range clause.
Adds a IN clause.
Adds a IS NULL clause.
Adds a raw JOIN clause.
Adds a LEFT OUTER JOIN clause.
Adds a raw LEFT OUTER JOIN clause.
Adds a HAVING clause.
Adds a raw HAVING clause.
Adds a raw OR HAVING clause.
Adds a raw ORDER BY clause.
Adds a raw ascending ORDER BY clause.
Adds a raw descending ORDER BY clause.
Executes a SELECT query and returns the first row of the result set or NULL if nothing is found.
Returns a single record from the database.
Creates a result set.
Executes a SELECT query and returns an array containing all of the result set rows.
Executes a SELECT query and returns the value of the chosen column of the first row of the result set.
Executes a SELECT query and returns an array containing the values of the indicated 0-indexed column.
Executes a SELECT query and returns an array where the first column is used as keys and the second as values.
Executes a SELECT query and returns a generator that lets you iterate over the results.
Sets the selected column of the query to the chosen aggreate.
Returns the number of distinct values of the chosen column.
Inserts data into the chosen table.
Inserts data into the chosen table and returns the auto increment id.
Updates data from the chosen table.
Increments column value.
Decrements column value.
Deletes data from the chosen table.
Returns a record using the value of its primary key.
Adds relations to eager load.
Removes relations to eager load.
Parses the count relation name and returns an array consisting of the relation name and the chosen alias.
Adds subqueries that count the number of related records for the chosen relations.
Returns a hydrated model.
Parses includes.
Load includes.
Returns hydrated models.
Calls a scope method on the model.
Details
at line 65
__construct(Connection $connection, ORM $model)
Constructor.
in Query at line 180
__clone()
Create a fresh compiler instance and clone set operation queries when we clone the query.
in Query at line 193
protected
reset()
Resets the query to its default state.
in Query at line 218
$this
inSubqueryContext()
Sets the query to subquery context.
in Query at line 230
static
setPaginationFactory(Closure|PaginationFactoryInterface $factory)
Sets the pagination factory.
in Query at line 240
static PaginationFactoryInterface
getPaginationFactory()
Gets the pagination factory.
in Query at line 257
Connection
getConnection()
Returns the connection instance.
in Query at line 277
array
getCommonTableExpressions()
Returns the common set operations.
in Query at line 287
array
getSetOperations()
Returns the set operations.
in Query at line 297
mixed
getTable()
Returns the database table.
in Query at line 307
bool
isDistinct()
Is it a distict select?
at line 79
array
getColumns()
Returns the columns from which we are fetching data.
in Query at line 327
array
getWheres()
Returns WHERE clauses.
in Query at line 337
array
getJoins()
Returns JOIN clauses.
in Query at line 347
array
getGroupings()
Returns GROUP BY clauses.
in Query at line 357
array
getHavings()
Returns HAVING clauses.
in Query at line 367
array
getOrderings()
Returns ORDER BY clauses.
in Query at line 377
int|null
getLimit()
Returns the limit.
in Query at line 387
int|null
getOffset()
Returns the offset.
in Query at line 397
bool|string|null
getLock()
Returns the lock.
in Query at line 407
string|null
getPrefix()
Returns the prefix.
in Query at line 419
$this
forCompiler(string $compilerClass, Closure $query)
Executes the closure if the compiler is of the correct class.
in Query at line 437
$this
with(string $name, array $columns, Subquery $query)
Adds a common table expression.
in Query at line 457
$this
withRecursive(string $name, array $columns, Subquery $query)
Adds a recursive common table expression.
in Query at line 470
protected $this
setOperation(string $operation)
Adds a set operation.
in Query at line 490
$this
union()
Adds a UNION operation.
in Query at line 500
$this
unionAll()
Adds a UNION ALL operation.
in Query at line 510
$this
intersect()
Adds a INTERSECT operation.
in Query at line 520
$this
intersectAll()
Adds a INTERSECT ALL operation.
in Query at line 530
$this
except()
Adds a EXCEPT operation.
in Query at line 540
$this
exceptAll()
Adds a EXCEPT ALL operation.
in Query at line 551
$this
table(array|Raw|Subquery|string|null $table)
Sets table we want to query.
in Query at line 586
$this
select(array $columns)
Sets the columns we want to select.
in Query at line 600
$this
selectRaw(string $sql, array $parameters = [])
Sets the columns we want to select using raw SQL.
in Query at line 612
$this
distinct()
Select distinct?
in Query at line 628
$this
where(array|Closure|string $column, string|null $operator = null, mixed $value = null, string $separator = 'AND')
Adds a WHERE clause.
in Query at line 667
$this
whereRaw(array|string $column, array|string|null $operator = null, string|null $raw = null, string $separator = 'AND')
Adds a raw WHERE clause.
in Query at line 692
$this
orWhere(array|Closure|string $column, string|null $operator = null, mixed $value = null)
Adds a OR WHERE clause.
in Query at line 705
$this
orWhereRaw(array|string $column, array|string|null $operator = null, string|null $raw = null)
Adds a raw OR WHERE clause.
in Query at line 719
$this
whereDate(string $column, string $operator, DateTimeInterface|string $date, string $separator = 'AND')
Adds a date comparison clause.
in Query at line 742
$this
orWhereDate(string $column, string $operator, DateTimeInterface|string $date)
Adds a date comparison clause.
in Query at line 756
$this
whereColumn(array|string $column1, string $operator, array|string $column2, string $separator = 'AND')
Adds a column comparison clause.
in Query at line 778
$this
orWhereColumn(array|string $column1, string $operator, array|string $column2)
Adds a column comparison clause.
in Query at line 793
$this
between(mixed $column, mixed $value1, mixed $value2, string $separator = 'AND', bool $not = false)
Adds a BETWEEN clause.
in Query at line 816
$this
orBetween(mixed $column, mixed $value1, mixed $value2)
Adds a OR BETWEEN clause.
in Query at line 829
$this
notBetween(mixed $column, mixed $value1, mixed $value2)
Adds a NOT BETWEEN clause.
in Query at line 842
$this
orNotBetween(mixed $column, mixed $value1, mixed $value2)
Adds a OR NOT BETWEEN clause.
in Query at line 857
$this
betweenDate(string $column, DateTimeInterface|string $date1, DateTimeInterface|string $date2, string $separator = 'AND', bool $not = false)
Adds a date range clause.
in Query at line 879
orBetweenDate(string $column, DateTimeInterface|string $date1, DateTimeInterface|string $date2)
Adds a date range clause.
in Query at line 891
notBetweenDate(string $column, DateTimeInterface|string $date1, DateTimeInterface|string $date2)
Adds a date range clause.
in Query at line 903
orNotBetweenDate(string $column, DateTimeInterface|string $date1, DateTimeInterface|string $date2)
Adds a date range clause.
in Query at line 917
$this
in(mixed $column, array|Raw|Subquery $values, string $separator = 'AND', bool $not = false)
Adds a IN clause.
in Query at line 962
$this
orNotIn(mixed $column, array|Raw|Subquery $values)
Adds a OR NOT IN clause.
in Query at line 975
$this
isNull(mixed $column, string $separator = 'AND', bool $not = false)
Adds a IS NULL clause.
in Query at line 994
$this
orIsNull(mixed $column)
Adds a OR IS NULL clause.
in Query at line 1005
$this
isNotNull(mixed $column)
Adds a IS NOT NULL clause.
in Query at line 1016
$this
orIsNotNull(mixed $column)
Adds a OR IS NOT NULL clause.
in Query at line 1029
$this
exists(Subquery $query, string $separator = 'AND', bool $not = false)
Adds a EXISTS clause.
at line 102
$this
join(string $table, Closure|string $column1 = null, string $operator = null, string $column2 = null, string $type = 'INNER', bool $raw = false)
Adds a JOIN clause.
in Query at line 1121
$this
joinRaw(string $table, string $column1, string $operator, string $raw, string $type = 'INNER')
Adds a raw JOIN clause.
in Query at line 1135
$this
leftJoin(string $table, Closure|string $column1 = null, string $operator = null, string $column2 = null)
Adds a LEFT OUTER JOIN clause.
in Query at line 1149
$this
leftJoinRaw(string $table, string $column1, string $operator, string $raw)
Adds a raw LEFT OUTER JOIN clause.
in Query at line 1160
$this
groupBy(array|string $columns)
Adds a GROUP BY clause.
in Query at line 1176
$this
having(Raw|string $column, string $operator, mixed $value, string $separator = 'AND')
Adds a HAVING clause.
in Query at line 1198
$this
havingRaw(string $raw, string $operator, mixed $value, string $separator = 'AND')
Adds a raw HAVING clause.
in Query at line 1211
$this
orHaving(string $column, string $operator, mixed $value)
Adds a OR HAVING clause.
in Query at line 1224
$this
orHavingRaw(string $raw, string $operator, mixed $value)
Adds a raw OR HAVING clause.
in Query at line 1236
$this
orderBy(array|Raw|string $columns, string $order = 'ASC')
Adds a ORDER BY clause.
in Query at line 1255
$this
orderByRaw(string $raw, array $parameters = [], string $order = 'ASC')
Adds a raw ORDER BY clause.
in Query at line 1266
$this
ascending(array|string $columns)
Adds an ascending ORDER BY clause.
in Query at line 1278
$this
ascendingRaw(string $raw, array $parameters = [])
Adds a raw ascending ORDER BY clause.
in Query at line 1289
$this
descending(array|string $columns)
Adds a descending ORDER BY clause.
in Query at line 1301
$this
descendingRaw(string $raw, array $parameters = [])
Adds a raw descending ORDER BY clause.
in Query at line 1311
$this
clearOrderings()
Clears the ordering clauses.
in Query at line 1324
$this
limit(int $limit)
Adds a LIMIT clause.
in Query at line 1337
$this
offset(int $offset)
Adds a OFFSET clause.
in Query at line 1350
$this
lock(bool|string $lock = true)
Enable lock.
in Query at line 1362
$this
sharedLock()
Enable shared lock.
in Query at line 1373
$this
prefix(string $prefix)
Adds a query prefix.
in Query at line 1386
protected mixed
fetchFirst(mixed ...$fetchMode)
Executes a SELECT query and returns the first row of the result set or NULL if nothing is found.
at line 477
mixed
first()
Returns a single record from the database.
at line 495
protected ResultSet
createResultSet(array $results)
Creates a result set.
in Query at line 1421
protected array|ResultSet
fetchAll(bool $returnResultSet, mixed ...$fetchMode)
Executes a SELECT query and returns an array containing all of the result set rows.
at line 505
ResultSet
all()
Returns a result set from the database.
in Query at line 1446
mixed
column(string $column = null)
Executes a SELECT query and returns the value of the chosen column of the first row of the result set.
in Query at line 1464
array
columns(string $column = null)
Executes a SELECT query and returns an array containing the values of the indicated 0-indexed column.
in Query at line 1483
array
pairs(string $key, string $value)
Executes a SELECT query and returns an array where the first column is used as keys and the second as values.
in Query at line 1498
protected Generator
fetchYield(mixed ...$fetchMode)
Executes a SELECT query and returns a generator that lets you iterate over the results.
at line 522
Generator
yield()
Returns a generator that lets you iterate over the results.
in Query at line 1520
protected int
paginationCount()
Returns the number of records that the query will return.
at line 36
ResultSet
paginate($itemsPerPage = null, array $options = [])
at line 533
batch(Closure $processor, int $batchSize = 1000, int $offsetStart = 0, int|null $offsetEnd = null)
Fetches data in batches and passes them to the processor closure.
at line 546
protected mixed
aggregate(string $function, array|string $column)
Sets the selected column of the query to the chosen aggreate.
Executes the query and returns the result if not in subquery context.
in Query at line 1629
mixed
min(string $column)
Returns the minimum value for the chosen column.
in Query at line 1640
mixed
max(string $column)
Returns the maximum value for the chosen column.
in Query at line 1651
mixed
sum(string $column)
Returns sum of all the values in the chosen column.
in Query at line 1662
mixed
avg(string $column)
Returns the average value for the chosen column.
in Query at line 1673
int
count(string $column = '*')
Returns the number of rows.
in Query at line 1684
int
countDistinct(array|string $column)
Returns the number of distinct values of the chosen column.
at line 115
bool
insert(array $values = [])
Inserts data into the chosen table.
in Query at line 1709
false|int
insertAndGetId(array $values, string $primaryKey = 'id')
Inserts data into the chosen table and returns the auto increment id.
at line 143
int
update(array $values)
Updates data from the chosen table.
at line 171
int
increment(string $column, int $increment = 1)
Increments column value.
at line 193
int
decrement(string $column, int $decrement = 1)
Decrements column value.
at line 215
int
delete()
Deletes data from the chosen table.
at line 94
ORM
getModel()
Returns the model.
at line 243
ORM|null
get(int|string $id, array $columns = [])
Returns a record using the value of its primary key.
at line 259
$this
including(array|false|string $includes)
Adds relations to eager load.
at line 301
$this
excluding(array|string|true $excludes)
Removes relations to eager load.
at line 336
protected array
parseRelationCountName(string $relation)
Parses the count relation name and returns an array consisting of the relation name and the chosen alias.
at line 354
$this
withCountOf(array|string $relations)
Adds subqueries that count the number of related records for the chosen relations.
at line 391
protected ORM
hydrateModel(array $result)
Returns a hydrated model.
at line 403
protected array
parseIncludes()
Parses includes.
at line 440
protected
loadIncludes(array $results)
Load includes.
at line 458
protected array
hydrateModelsAndLoadIncludes(mixed $results)
Returns hydrated models.
at line 564
$this
scope(string $scope, mixed ...$arguments)
Calls a scope method on the model.