class Query

Query builder.

Properties

protected Connection $connection Database connection.
protected HelperInterface $helper Query helper.
protected Compiler $compiler Query compiler.
protected mixed $table Database table.
protected bool $distinct Select distinct?
protected array $commonTableExpressions Common table expressions.
protected array $setOperations Set operations.
protected array $columns Columns from which we are fetching data.
protected array $wheres WHERE clauses.
protected array $joins JOIN clauses.
protected array $groupings GROUP BY clauses.
protected array $havings HAVING clauses.
protected array $orderings ORDER BY clauses.
protected int|null $limit Limit.
protected int|null $offset Offset.
protected bool|string|null $lock Lock.
protected string|null $prefix Prefix.
protected bool $inSubqueryContext Is the query in subquery context?
static protected Closure|PaginationFactoryInterface $paginationFactory Pagination factory.

Methods

__construct(Connection $connection)

Constructor.

__clone()

Create a fresh compiler instance and clone set operation queries when we clone the query.

reset()

Resets the query to its default state.

newInstance()

Returns a new query builder instance.

$this
inSubqueryContext()

Sets the query to subquery context.

static 
setPaginationFactory(Closure|PaginationFactoryInterface $factory)

Sets the pagination factory.

getPaginationFactory()

Gets the pagination factory.

getConnection()

Returns the connection instance.

getCompiler()

Returns query compiler instance.

array
getCommonTableExpressions()

Returns the common set operations.

array
getSetOperations()

Returns the set operations.

mixed
getTable()

Returns the database table.

bool
isDistinct()

Is it a distict select?

array
getColumns()

Returns the columns from which we are fetching data.

array
getWheres()

Returns WHERE clauses.

array
getJoins()

Returns JOIN clauses.

array
getGroupings()

Returns GROUP BY clauses.

array
getHavings()

Returns HAVING clauses.

array
getOrderings()

Returns ORDER BY clauses.

int|null
getLimit()

Returns the limit.

int|null
getOffset()

Returns the offset.

bool|string|null
getLock()

Returns the lock.

string|null
getPrefix()

Returns the prefix.

$this
forCompiler(string $compilerClass, Closure $query)

Executes the closure if the compiler is of the correct class.

$this
with(string $name, array $columns, Subquery $query)

Adds a common table expression.

$this
withRecursive(string $name, array $columns, Subquery $query)

Adds a recursive common table expression.

$this
setOperation(string $operation)

Adds a set operation.

$this
union()

Adds a UNION operation.

$this
unionAll()

Adds a UNION ALL operation.

$this
intersect()

Adds a INTERSECT operation.

$this
intersectAll()

Adds a INTERSECT ALL operation.

$this
except()

Adds a EXCEPT operation.

$this
exceptAll()

Adds a EXCEPT ALL operation.

$this
table(array|Raw|Subquery|string|null $table)

Sets table we want to query.

$this
from(array|Raw|Subquery|string|null $table)

Alias of Query::table().

$this
into(array|Raw|Subquery|string|null $table)

Alias of Query::table().

$this
select(array $columns)

Sets the columns we want to select.

$this
selectRaw(string $sql, array $parameters = [])

Sets the columns we want to select using raw SQL.

$this
distinct()

Select distinct?

$this
where(array|Closure|string $column, string|null $operator = null, mixed $value = null, string $separator = 'AND')

Adds a WHERE clause.

$this
whereRaw(array|string $column, array|string|null $operator = null, string|null $raw = null, string $separator = 'AND')

Adds a raw WHERE clause.

$this
orWhere(array|Closure|string $column, string|null $operator = null, mixed $value = null)

Adds a OR WHERE clause.

$this
orWhereRaw(array|string $column, array|string|null $operator = null, string|null $raw = null)

Adds a raw OR WHERE clause.

$this
whereDate(string $column, string $operator, DateTimeInterface|string $date, string $separator = 'AND')

Adds a date comparison clause.

$this
orWhereDate(string $column, string $operator, DateTimeInterface|string $date)

Adds a date comparison clause.

$this
whereColumn(array|string $column1, string $operator, array|string $column2, string $separator = 'AND')

Adds a column comparison clause.

$this
orWhereColumn(array|string $column1, string $operator, array|string $column2)

Adds a column comparison clause.

$this
between(mixed $column, mixed $value1, mixed $value2, string $separator = 'AND', bool $not = false)

Adds a BETWEEN clause.

$this
orBetween(mixed $column, mixed $value1, mixed $value2)

Adds a OR BETWEEN clause.

$this
notBetween(mixed $column, mixed $value1, mixed $value2)

Adds a NOT BETWEEN clause.

$this
orNotBetween(mixed $column, mixed $value1, mixed $value2)

Adds a OR NOT BETWEEN clause.

$this
betweenDate(string $column, DateTimeInterface|string $date1, DateTimeInterface|string $date2, string $separator = 'AND', bool $not = false)

Adds a date range clause.

orBetweenDate(string $column, DateTimeInterface|string $date1, DateTimeInterface|string $date2)

Adds a date range clause.

notBetweenDate(string $column, DateTimeInterface|string $date1, DateTimeInterface|string $date2)

Adds a date range clause.

orNotBetweenDate(string $column, DateTimeInterface|string $date1, DateTimeInterface|string $date2)

Adds a date range clause.

$this
in(mixed $column, array|Raw|Subquery $values, string $separator = 'AND', bool $not = false)

Adds a IN clause.

$this
orIn(mixed $column, array|Raw|Subquery $values)

Adds a OR IN clause.

$this
notIn(mixed $column, array|Raw|Subquery $values)

Adds a NOT IN clause.

$this
orNotIn(mixed $column, array|Raw|Subquery $values)

Adds a OR NOT IN clause.

$this
isNull(mixed $column, string $separator = 'AND', bool $not = false)

Adds a IS NULL clause.

$this
orIsNull(mixed $column)

Adds a OR IS NULL clause.

$this
isNotNull(mixed $column)

Adds a IS NOT NULL clause.

$this
orIsNotNull(mixed $column)

Adds a OR IS NOT NULL clause.

$this
exists(Subquery $query, string $separator = 'AND', bool $not = false)

Adds a EXISTS clause.

$this
orExists(Subquery $query)

Adds a OR EXISTS clause.

$this
notExists(Subquery $query)

Adds a NOT EXISTS clause.

$this
orNotExists(Subquery $query)

Adds a OR NOT EXISTS clause.

$this
join(string $table, Closure|string $column1 = null, string $operator = null, string $column2 = null, string $type = 'INNER', bool $raw = false)

Adds a JOIN clause.

$this
joinRaw(string $table, string $column1, string $operator, string $raw, string $type = 'INNER')

Adds a raw JOIN clause.

$this
leftJoin(string $table, Closure|string $column1 = null, string $operator = null, string $column2 = null)

Adds a LEFT OUTER JOIN clause.

$this
leftJoinRaw(string $table, string $column1, string $operator, string $raw)

Adds a raw LEFT OUTER JOIN clause.

$this
groupBy(array|string $columns)

Adds a GROUP BY clause.

$this
having(Raw|string $column, string $operator, mixed $value, string $separator = 'AND')

Adds a HAVING clause.

$this
havingRaw(string $raw, string $operator, mixed $value, string $separator = 'AND')

Adds a raw HAVING clause.

$this
orHaving(string $column, string $operator, mixed $value)

Adds a OR HAVING clause.

$this
orHavingRaw(string $raw, string $operator, mixed $value)

Adds a raw OR HAVING clause.

$this
orderBy(array|Raw|string $columns, string $order = 'ASC')

Adds a ORDER BY clause.

$this
orderByRaw(string $raw, array $parameters = [], string $order = 'ASC')

Adds a raw ORDER BY clause.

$this
ascending(array|string $columns)

Adds an ascending ORDER BY clause.

$this
ascendingRaw(string $raw, array $parameters = [])

Adds a raw ascending ORDER BY clause.

$this
descending(array|string $columns)

Adds a descending ORDER BY clause.

$this
descendingRaw(string $raw, array $parameters = [])

Adds a raw descending ORDER BY clause.

$this
clearOrderings()

Clears the ordering clauses.

$this
limit(int $limit)

Adds a LIMIT clause.

$this
offset(int $offset)

Adds a OFFSET clause.

$this
lock(bool|string $lock = true)

Enable lock.

$this
sharedLock()

Enable shared lock.

$this
prefix(string $prefix)

Adds a query prefix.

mixed
fetchFirst(mixed ...$fetchMode)

Executes a SELECT query and returns the first row of the result set or NULL if nothing is found.

mixed
first()

Executes a SELECT query and returns the first row of the result set or NULL if nothing is found.

createResultSet(array $results)

Creates a result set.

array|ResultSet
fetchAll(bool $returnResultSet, mixed ...$fetchMode)

Executes a SELECT query and returns an array containing all of the result set rows.

all()

Executes a SELECT query and returns an array containing all of the result set rows.

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.

array
columns(string $column = null)

Executes a SELECT query and returns an array containing the values of the indicated 0-indexed column.

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.

fetchYield(mixed ...$fetchMode)

Executes a SELECT query and returns a generator that lets you iterate over the results.

yield()

Executes a SELECT query and returns a generator that lets you iterate over the results.

int
paginationCount()

Returns the number of records that the query will return.

paginate(int|null $itemsPerPage = null, array $options = [])

Paginates the results using a pagination instance.

batch(Closure $processor, int $batchSize = 1000, int $offsetStart = 0, int|null $offsetEnd = null)

Fetches data in batches and passes them to the processor closure.

mixed
aggregate(string $function, array|string $column)

Sets the selected column of the query to the chosen aggreate.

mixed
min(string $column)

Returns the minimum value for the chosen column.

mixed
max(string $column)

Returns the maximum value for the chosen column.

mixed
sum(string $column)

Returns sum of all the values in the chosen column.

mixed
avg(string $column)

Returns the average value for the chosen column.

int
count(string $column = '*')

Returns the number of rows.

int
countDistinct(array|string $column)

Returns the number of distinct values of the chosen column.

bool
insert(array $values = [])

Inserts data into the chosen table.

false|int
insertAndGetId(array $values, string $primaryKey = 'id')

Inserts data into the chosen table and returns the auto increment id.

int
update(array $values)

Updates data from the chosen table.

int
increment(string $column, int $increment = 1)

Increments column value.

int
decrement(string $column, int $decrement = 1)

Decrements column value.

int
delete()

Deletes data from the chosen table.

Details

at line 168
__construct(Connection $connection)

Constructor.

Parameters

Connection $connection Database connection

at line 180
__clone()

Create a fresh compiler instance and clone set operation queries when we clone the query.

at line 193
protected reset()

Resets the query to its default state.

at line 208
Query newInstance()

Returns a new query builder instance.

Return Value

Query

at line 218
$this inSubqueryContext()

Sets the query to subquery context.

Return Value

$this

at line 230
static setPaginationFactory(Closure|PaginationFactoryInterface $factory)

Sets the pagination factory.

Parameters

Closure|PaginationFactoryInterface $factory Pagination factory

at line 240
static PaginationFactoryInterface getPaginationFactory()

Gets the pagination factory.

at line 257
Connection getConnection()

Returns the connection instance.

Return Value

Connection

at line 267
Compiler getCompiler()

Returns query compiler instance.

Return Value

Compiler

at line 277
array getCommonTableExpressions()

Returns the common set operations.

Return Value

array

at line 287
array getSetOperations()

Returns the set operations.

Return Value

array

at line 297
mixed getTable()

Returns the database table.

Return Value

mixed

at line 307
bool isDistinct()

Is it a distict select?

Return Value

bool

at line 317
array getColumns()

Returns the columns from which we are fetching data.

Return Value

array

at line 327
array getWheres()

Returns WHERE clauses.

Return Value

array

at line 337
array getJoins()

Returns JOIN clauses.

Return Value

array

at line 347
array getGroupings()

Returns GROUP BY clauses.

Return Value

array

at line 357
array getHavings()

Returns HAVING clauses.

Return Value

array

at line 367
array getOrderings()

Returns ORDER BY clauses.

Return Value

array

at line 377
int|null getLimit()

Returns the limit.

Return Value

int|null

at line 387
int|null getOffset()

Returns the offset.

Return Value

int|null

at line 397
bool|string|null getLock()

Returns the lock.

Return Value

bool|string|null

at line 407
string|null getPrefix()

Returns the prefix.

Return Value

string|null

at line 419
$this forCompiler(string $compilerClass, Closure $query)

Executes the closure if the compiler is of the correct class.

Parameters

string $compilerClass Compiler class name
Closure $query Closure

Return Value

$this

at line 437
$this with(string $name, array $columns, Subquery $query)

Adds a common table expression.

Parameters

string $name Table name
array $columns Column names
Subquery $query Query

Return Value

$this

at line 457
$this withRecursive(string $name, array $columns, Subquery $query)

Adds a recursive common table expression.

Parameters

string $name Table name
array $columns Column names
Subquery $query Query

Return Value

$this

at line 470
protected $this setOperation(string $operation)

Adds a set operation.

Parameters

string $operation Operation

Return Value

$this

at line 490
$this union()

Adds a UNION operation.

Return Value

$this

at line 500
$this unionAll()

Adds a UNION ALL operation.

Return Value

$this

at line 510
$this intersect()

Adds a INTERSECT operation.

Return Value

$this

at line 520
$this intersectAll()

Adds a INTERSECT ALL operation.

Return Value

$this

at line 530
$this except()

Adds a EXCEPT operation.

Return Value

$this

at line 540
$this exceptAll()

Adds a EXCEPT ALL operation.

Return Value

$this

at line 551
$this table(array|Raw|Subquery|string|null $table)

Sets table we want to query.

Parameters

array|Raw|Subquery|string|null $table Database table or subquery

Return Value

$this

at line 564
$this from(array|Raw|Subquery|string|null $table)

Alias of Query::table().

Parameters

array|Raw|Subquery|string|null $table Database table or subquery

Return Value

$this

at line 575
$this into(array|Raw|Subquery|string|null $table)

Alias of Query::table().

Parameters

array|Raw|Subquery|string|null $table Database table or subquery

Return Value

$this

at line 586
$this select(array $columns)

Sets the columns we want to select.

Parameters

array $columns Array of columns we want to select from

Return Value

$this

at line 600
$this selectRaw(string $sql, array $parameters = [])

Sets the columns we want to select using raw SQL.

Parameters

string $sql Raw sql
array $parameters Parameters

Return Value

$this

at line 612
$this distinct()

Select distinct?

Return Value

$this

at line 628
$this where(array|Closure|string $column, string|null $operator = null, mixed $value = null, string $separator = 'AND')

Adds a WHERE clause.

Parameters

array|Closure|string $column Column name, an array of column names or closure
string|null $operator Operator
mixed $value Value
string $separator Clause separator

Return Value

$this

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.

Parameters

array|string $column Column name, an array of column names or raw SQL
array|string|null $operator Operator or parameters
string|null $raw Raw SQL
string $separator Clause separator

Return Value

$this

at line 692
$this orWhere(array|Closure|string $column, string|null $operator = null, mixed $value = null)

Adds a OR WHERE clause.

Parameters

array|Closure|string $column Column name, an array of column names or closure
string|null $operator Operator
mixed $value Value

Return Value

$this

at line 705
$this orWhereRaw(array|string $column, array|string|null $operator = null, string|null $raw = null)

Adds a raw OR WHERE clause.

Parameters

array|string $column Column name, and array of column names or raw SQL
array|string|null $operator Operator or parameters
string|null $raw Raw SQL

Return Value

$this

at line 719
$this whereDate(string $column, string $operator, DateTimeInterface|string $date, string $separator = 'AND')

Adds a date comparison clause.

Parameters

string $column Column name
string $operator Operator
DateTimeInterface|string $date Date
string $separator Separator

Return Value

$this

at line 742
$this orWhereDate(string $column, string $operator, DateTimeInterface|string $date)

Adds a date comparison clause.

Parameters

string $column Column name
string $operator Operator
DateTimeInterface|string $date Date

Return Value

$this

at line 756
$this whereColumn(array|string $column1, string $operator, array|string $column2, string $separator = 'AND')

Adds a column comparison clause.

Parameters

array|string $column1 Column name of array of column names
string $operator Operator
array|string $column2 Column name of array of column names
string $separator Separator

Return Value

$this

at line 778
$this orWhereColumn(array|string $column1, string $operator, array|string $column2)

Adds a column comparison clause.

Parameters

array|string $column1 Column name of array of column names
string $operator Operator
array|string $column2 Column name of array of column names

Return Value

$this

at line 793
$this between(mixed $column, mixed $value1, mixed $value2, string $separator = 'AND', bool $not = false)

Adds a BETWEEN clause.

Parameters

mixed $column Column name
mixed $value1 First value
mixed $value2 Second value
string $separator Clause separator
bool $not Not between?

Return Value

$this

at line 816
$this orBetween(mixed $column, mixed $value1, mixed $value2)

Adds a OR BETWEEN clause.

Parameters

mixed $column Column name
mixed $value1 First value
mixed $value2 Second value

Return Value

$this

at line 829
$this notBetween(mixed $column, mixed $value1, mixed $value2)

Adds a NOT BETWEEN clause.

Parameters

mixed $column Column name
mixed $value1 First value
mixed $value2 Second value

Return Value

$this

at line 842
$this orNotBetween(mixed $column, mixed $value1, mixed $value2)

Adds a OR NOT BETWEEN clause.

Parameters

mixed $column Column name
mixed $value1 First value
mixed $value2 Second value

Return Value

$this

at line 857
$this betweenDate(string $column, DateTimeInterface|string $date1, DateTimeInterface|string $date2, string $separator = 'AND', bool $not = false)

Adds a date range clause.

Parameters

string $column Column name
DateTimeInterface|string $date1 First date
DateTimeInterface|string $date2 Second date
string $separator Separator
bool $not Not between?

Return Value

$this

at line 879
orBetweenDate(string $column, DateTimeInterface|string $date1, DateTimeInterface|string $date2)

Adds a date range clause.

Parameters

string $column Column name
DateTimeInterface|string $date1 First date
DateTimeInterface|string $date2 Second date

at line 891
notBetweenDate(string $column, DateTimeInterface|string $date1, DateTimeInterface|string $date2)

Adds a date range clause.

Parameters

string $column Column name
DateTimeInterface|string $date1 First date
DateTimeInterface|string $date2 Second date

at line 903
orNotBetweenDate(string $column, DateTimeInterface|string $date1, DateTimeInterface|string $date2)

Adds a date range clause.

Parameters

string $column Column name
DateTimeInterface|string $date1 First date
DateTimeInterface|string $date2 Second date

at line 917
$this in(mixed $column, array|Raw|Subquery $values, string $separator = 'AND', bool $not = false)

Adds a IN clause.

Parameters

mixed $column Column name
array|Raw|Subquery $values Array of values or Subquery
string $separator Clause separator
bool $not Not in?

Return Value

$this

at line 938
$this orIn(mixed $column, array|Raw|Subquery $values)

Adds a OR IN clause.

Parameters

mixed $column Column name
array|Raw|Subquery $values Array of values or Subquery

Return Value

$this

at line 950
$this notIn(mixed $column, array|Raw|Subquery $values)

Adds a NOT IN clause.

Parameters

mixed $column Column name
array|Raw|Subquery $values Array of values or Subquery

Return Value

$this

at line 962
$this orNotIn(mixed $column, array|Raw|Subquery $values)

Adds a OR NOT IN clause.

Parameters

mixed $column Column name
array|Raw|Subquery $values Array of values or Subquery

Return Value

$this

at line 975
$this isNull(mixed $column, string $separator = 'AND', bool $not = false)

Adds a IS NULL clause.

Parameters

mixed $column Column name
string $separator Clause separator
bool $not Not in?

Return Value

$this

at line 994
$this orIsNull(mixed $column)

Adds a OR IS NULL clause.

Parameters

mixed $column Column name

Return Value

$this

at line 1005
$this isNotNull(mixed $column)

Adds a IS NOT NULL clause.

Parameters

mixed $column Column name

Return Value

$this

at line 1016
$this orIsNotNull(mixed $column)

Adds a OR IS NOT NULL clause.

Parameters

mixed $column Column name

Return Value

$this

at line 1029
$this exists(Subquery $query, string $separator = 'AND', bool $not = false)

Adds a EXISTS clause.

Parameters

Subquery $query Subquery
string $separator Clause separator
bool $not Not exists?

Return Value

$this

at line 1048
$this orExists(Subquery $query)

Adds a OR EXISTS clause.

Parameters

Subquery $query Subquery

Return Value

$this

at line 1059
$this notExists(Subquery $query)

Adds a NOT EXISTS clause.

Parameters

Subquery $query Subquery

Return Value

$this

at line 1070
$this orNotExists(Subquery $query)

Adds a OR NOT EXISTS clause.

Parameters

Subquery $query Subquery

Return Value

$this

at line 1086
$this join(string $table, Closure|string $column1 = null, string $operator = null, string $column2 = null, string $type = 'INNER', bool $raw = false)

Adds a JOIN clause.

Parameters

string $table Table name
Closure|string $column1 Column name or closure
string $operator Operator
string $column2 Column name
string $type Join type
bool $raw Raw join?

Return Value

$this

at line 1121
$this joinRaw(string $table, string $column1, string $operator, string $raw, string $type = 'INNER')

Adds a raw JOIN clause.

Parameters

string $table Table name
string $column1 Column name or closure
string $operator Operator
string $raw Raw SQL
string $type Join type

Return Value

$this

at line 1135
$this leftJoin(string $table, Closure|string $column1 = null, string $operator = null, string $column2 = null)

Adds a LEFT OUTER JOIN clause.

Parameters

string $table Table name
Closure|string $column1 Column name or closure
string $operator Operator
string $column2 Column name

Return Value

$this

at line 1149
$this leftJoinRaw(string $table, string $column1, string $operator, string $raw)

Adds a raw LEFT OUTER JOIN clause.

Parameters

string $table Table name
string $column1 Column name or closure
string $operator Operator
string $raw Raw SQL

Return Value

$this

at line 1160
$this groupBy(array|string $columns)

Adds a GROUP BY clause.

Parameters

array|string $columns Column name or array of column names

Return Value

$this

at line 1176
$this having(Raw|string $column, string $operator, mixed $value, string $separator = 'AND')

Adds a HAVING clause.

Parameters

Raw|string $column Column name
string $operator Operator
mixed $value Value
string $separator Clause separator

Return Value

$this

at line 1198
$this havingRaw(string $raw, string $operator, mixed $value, string $separator = 'AND')

Adds a raw HAVING clause.

Parameters

string $raw Raw SQL
string $operator Operator
mixed $value Value
string $separator Clause separator

Return Value

$this

at line 1211
$this orHaving(string $column, string $operator, mixed $value)

Adds a OR HAVING clause.

Parameters

string $column Column name
string $operator Operator
mixed $value Value

Return Value

$this

at line 1224
$this orHavingRaw(string $raw, string $operator, mixed $value)

Adds a raw OR HAVING clause.

Parameters

string $raw Raw SQL
string $operator Operator
mixed $value Value

Return Value

$this

at line 1236
$this orderBy(array|Raw|string $columns, string $order = 'ASC')

Adds a ORDER BY clause.

Parameters

array|Raw|string $columns Column name or array of column names
string $order Sorting order

Return Value

$this

at line 1255
$this orderByRaw(string $raw, array $parameters = [], string $order = 'ASC')

Adds a raw ORDER BY clause.

Parameters

string $raw Raw SQL
array $parameters Parameters
string $order Sorting order

Return Value

$this

at line 1266
$this ascending(array|string $columns)

Adds an ascending ORDER BY clause.

Parameters

array|string $columns Column name or array of column names

Return Value

$this

at line 1278
$this ascendingRaw(string $raw, array $parameters = [])

Adds a raw ascending ORDER BY clause.

Parameters

string $raw Raw SQL
array $parameters Parameters

Return Value

$this

at line 1289
$this descending(array|string $columns)

Adds a descending ORDER BY clause.

Parameters

array|string $columns Column name or array of column names

Return Value

$this

at line 1301
$this descendingRaw(string $raw, array $parameters = [])

Adds a raw descending ORDER BY clause.

Parameters

string $raw Raw SQL
array $parameters Parameters

Return Value

$this

at line 1311
$this clearOrderings()

Clears the ordering clauses.

Return Value

$this

at line 1324
$this limit(int $limit)

Adds a LIMIT clause.

Parameters

int $limit Limit

Return Value

$this

at line 1337
$this offset(int $offset)

Adds a OFFSET clause.

Parameters

int $offset Offset

Return Value

$this

at line 1350
$this lock(bool|string $lock = true)

Enable lock.

Parameters

bool|string $lock TRUE for exclusive, FALSE for shared and string for custom

Return Value

$this

at line 1362
$this sharedLock()

Enable shared lock.

Return Value

$this

at line 1373
$this prefix(string $prefix)

Adds a query prefix.

Parameters

string $prefix Prefix

Return Value

$this

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.

Parameters

mixed ...$fetchMode Fetch mode

Return Value

mixed

at line 1398
mixed first()

Executes a SELECT query and returns the first row of the result set or NULL if nothing is found.

Return Value

mixed

at line 1409
protected ResultSet createResultSet(array $results)

Creates a result set.

Parameters

array $results Results

Return Value

ResultSet

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.

Parameters

bool $returnResultSet Return result set?
mixed ...$fetchMode Fetch mode

Return Value

array|ResultSet

at line 1435
ResultSet all()

Executes a SELECT query and returns an array containing all of the result set rows.

Return Value

ResultSet

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.

Parameters

string $column The column to select

Return Value

mixed

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.

Parameters

string $column The column to select

Return Value

array

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.

Parameters

string $key The column to use as keys
string $value The column to use as values

Return Value

array

at line 1498
protected Generator fetchYield(mixed ...$fetchMode)

Executes a SELECT query and returns a generator that lets you iterate over the results.

Parameters

mixed ...$fetchMode Fetch mode

Return Value

Generator

at line 1510
Generator yield()

Executes a SELECT query and returns a generator that lets you iterate over the results.

Return Value

Generator

at line 1520
protected int paginationCount()

Returns the number of records that the query will return.

Return Value

int

at line 1542
ResultSet paginate(int|null $itemsPerPage = null, array $options = [])

Paginates the results using a pagination instance.

Parameters

int|null $itemsPerPage Number of items per page
array $options Pagination options

Return Value

ResultSet

at line 1570
batch(Closure $processor, int $batchSize = 1000, int $offsetStart = 0, int|null $offsetEnd = null)

Fetches data in batches and passes them to the processor closure.

Parameters

Closure $processor Closure that processes the results
int $batchSize Batch size
int $offsetStart Offset start
int|null $offsetEnd Offset end

at line 1611
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.

Parameters

string $function Aggregate function
array|string $column Column name or array of column names

Return Value

mixed

at line 1629
mixed min(string $column)

Returns the minimum value for the chosen column.

Parameters

string $column Column name

Return Value

mixed

at line 1640
mixed max(string $column)

Returns the maximum value for the chosen column.

Parameters

string $column Column name

Return Value

mixed

at line 1651
mixed sum(string $column)

Returns sum of all the values in the chosen column.

Parameters

string $column Column name

Return Value

mixed

at line 1662
mixed avg(string $column)

Returns the average value for the chosen column.

Parameters

string $column Column name

Return Value

mixed

at line 1673
int count(string $column = '*')

Returns the number of rows.

Parameters

string $column Column name

Return Value

int

at line 1684
int countDistinct(array|string $column)

Returns the number of distinct values of the chosen column.

Parameters

array|string $column Column name or array of column names

Return Value

int

at line 1695
bool insert(array $values = [])

Inserts data into the chosen table.

Parameters

array $values Associative array of column values

Return Value

bool

at line 1709
false|int insertAndGetId(array $values, string $primaryKey = 'id')

Inserts data into the chosen table and returns the auto increment id.

Parameters

array $values Associative array of column values
string $primaryKey Primary key

Return Value

false|int

at line 1720
int update(array $values)

Updates data from the chosen table.

Parameters

array $values Associative array of column values

Return Value

int

at line 1734
int increment(string $column, int $increment = 1)

Increments column value.

Parameters

string $column Column name
int $increment Increment value

Return Value

int

at line 1746
int decrement(string $column, int $decrement = 1)

Decrements column value.

Parameters

string $column Column name
int $decrement Decrement value

Return Value

int

at line 1756
int delete()

Deletes data from the chosen table.

Return Value

int