PHP Class Pagekit\Database\Query\QueryBuilder

Mostrar archivo Open project: pagekit/pagekit Class Usage Examples

Protected Properties

Property Type Description
$connection Pagekit\Database\Connection The Connection.
$params array The query parameters.
$parts array The query parts.

Public Methods

Method Description
__construct ( Pagekit\Database\Connection $connection ) Constructor.
__toString ( ) {@see QueryBuilder::getSQL}
addPart ( string $name, mixed $parts ) : self Adds a query part.
aggregate ( string $function, string $column ) : mixed Execute the query with an aggregate function.
avg ( string $column ) : mixed Execute the query and get the "avg" result.
count ( string $column = '*' ) : integer Execute the query and get the "count" result.
delete ( ) : integer Execute the "delete" query.
execute ( mixed $columns = ['*'] ) : Doctrine\DBAL\Driver\Statement Execute the "select" query.
first ( mixed $columns = ['*'] ) : mixed Execute the query and get the first result.
from ( string $table ) : self Creates and sets a "from" to the query.
get ( mixed $columns = ['*'] ) : array Execute the query and get all results.
getConnection ( ) : Pagekit\Database\Connection Gets the connection for the query builder.
getPart ( string $name ) : mixed Gets a query part by its name.
getParts ( ) : array Gets all query parts.
getSQL ( ) : string Gets the query SQL.
groupBy ( mixed $groupBy ) : self Creates and adds a "group by" to the query.
having ( mixed $having, string $type = CompositeExpression::TYPE_AND ) : self Creates and adds a "having" to the query.
innerJoin ( string $table, string $condition = null ) : self Creates and adds an "inner join" to the query.
join ( string $table, string $condition = null, string $type = 'inner' ) : self Creates and adds a "join" to the query.
leftJoin ( string $table, string $condition = null ) : self Creates and adds a "left join" to the query.
limit ( integer $limit ) : self Sets the limit of the query.
max ( string $column ) : mixed Execute the query and get the "max" result.
min ( string $column ) : mixed Execute the query and get the "min" result.
offset ( integer $offset ) : self Sets the offset of the query.
orHaving ( mixed $having ) : self Creates and adds a "or having" to the query.
orWhere ( mixed $condition, array $params = [] ) : self Creates and adds a "or where" to the query.
orWhereExists ( Closure $callback, boolean $not = false ) : self Creates and adds a "or where exists" to the query.
orWhereIn ( string $column, mixed $values, boolean $not = false ) : self Creates and adds a "or where in" to the query.
orderBy ( string $sort, string $order = null ) : self Creates and adds an "order by" to the query.
params ( array $params = null ) : array | self Get or set multiple query parameters.
rightJoin ( string $table, string $condition = null ) : self Creates and adds a "right join" to the query.
select ( mixed $columns = ['*'] ) : self Creates and adds a "select" to the query.
setPart ( string $name, mixed $parts ) : self Sets a query part and replaces all previous values.
sum ( string $column ) : mixed Execute the query and get the "sum" result.
update ( array $values ) : integer Execute the "update" query with the given values.
where ( mixed $condition, array $params = [] ) : self Creates and adds a "where" to the query.
whereExists ( Closure $callback, boolean $not = false, string $type = null ) : self Creates and adds a "where exists" to the query.
whereIn ( string $column, mixed $values, boolean $not = false, string $type = null ) : self Creates and adds a "where in" to the query.
whereInSet ( string $column, mixed $values, boolean $not = false, string $type = null ) : self Creates and adds a "where FIND_IN_SET" equivalent to the query.

Protected Methods

Method Description
addWhere ( mixed $condition, array $params, string $type = null ) : self Creates and adds a "where" to the query.
executeQuery ( string $type = 'select' ) : mixed Execute the query as select, update or delete.
getSQLForDelete ( ) : string Creates the "delete" SQL string from the query parts.
getSQLForSelect ( ) : string Creates the "select" SQL string from the query parts.
getSQLForUpdate ( ) : string Creates the "update" SQL string from the query parts.
guessParamTypes ( array $params = [] ) : array Tries to guess param types
newQuery ( ) : QueryBuilder Creates a new query builder.
parameter ( $name )

Method Details

__construct() public method

Constructor.
public __construct ( Pagekit\Database\Connection $connection )
$connection Pagekit\Database\Connection

__toString() public method

{@see QueryBuilder::getSQL}
public __toString ( )

addPart() public method

Adds a query part.
public addPart ( string $name, mixed $parts ) : self
$name string
$parts mixed
return self

addWhere() protected method

Creates and adds a "where" to the query.
protected addWhere ( mixed $condition, array $params, string $type = null ) : self
$condition mixed
$params array
$type string
return self

aggregate() public method

Execute the query with an aggregate function.
public aggregate ( string $function, string $column ) : mixed
$function string
$column string
return mixed

avg() public method

Execute the query and get the "avg" result.
public avg ( string $column ) : mixed
$column string
return mixed

count() public method

Execute the query and get the "count" result.
public count ( string $column = '*' ) : integer
$column string
return integer

delete() public method

Execute the "delete" query.
public delete ( ) : integer
return integer

execute() public method

Execute the "select" query.
public execute ( mixed $columns = ['*'] ) : Doctrine\DBAL\Driver\Statement
$columns mixed
return Doctrine\DBAL\Driver\Statement

executeQuery() protected method

Execute the query as select, update or delete.
protected executeQuery ( string $type = 'select' ) : mixed
$type string
return mixed

first() public method

Execute the query and get the first result.
public first ( mixed $columns = ['*'] ) : mixed
$columns mixed
return mixed

from() public method

Creates and sets a "from" to the query.
public from ( string $table ) : self
$table string
return self

get() public method

Execute the query and get all results.
public get ( mixed $columns = ['*'] ) : array
$columns mixed
return array

getConnection() public method

Gets the connection for the query builder.
public getConnection ( ) : Pagekit\Database\Connection
return Pagekit\Database\Connection

getPart() public method

Gets a query part by its name.
public getPart ( string $name ) : mixed
$name string
return mixed

getParts() public method

Gets all query parts.
public getParts ( ) : array
return array

getSQL() public method

Gets the query SQL.
public getSQL ( ) : string
return string

getSQLForDelete() protected method

Creates the "delete" SQL string from the query parts.
protected getSQLForDelete ( ) : string
return string

getSQLForSelect() protected method

Creates the "select" SQL string from the query parts.
protected getSQLForSelect ( ) : string
return string

getSQLForUpdate() protected method

Creates the "update" SQL string from the query parts.
protected getSQLForUpdate ( ) : string
return string

groupBy() public method

Creates and adds a "group by" to the query.
public groupBy ( mixed $groupBy ) : self
$groupBy mixed
return self

guessParamTypes() protected method

Tries to guess param types
protected guessParamTypes ( array $params = [] ) : array
$params array
return array

having() public method

Creates and adds a "having" to the query.
public having ( mixed $having, string $type = CompositeExpression::TYPE_AND ) : self
$having mixed
$type string
return self

innerJoin() public method

Creates and adds an "inner join" to the query.
public innerJoin ( string $table, string $condition = null ) : self
$table string
$condition string
return self

join() public method

Creates and adds a "join" to the query.
public join ( string $table, string $condition = null, string $type = 'inner' ) : self
$table string
$condition string
$type string
return self

leftJoin() public method

Creates and adds a "left join" to the query.
public leftJoin ( string $table, string $condition = null ) : self
$table string
$condition string
return self

limit() public method

Sets the limit of the query.
public limit ( integer $limit ) : self
$limit integer
return self

max() public method

Execute the query and get the "max" result.
public max ( string $column ) : mixed
$column string
return mixed

min() public method

Execute the query and get the "min" result.
public min ( string $column ) : mixed
$column string
return mixed

newQuery() protected method

Creates a new query builder.
protected newQuery ( ) : QueryBuilder
return QueryBuilder

offset() public method

Sets the offset of the query.
public offset ( integer $offset ) : self
$offset integer
return self

orHaving() public method

Creates and adds a "or having" to the query.
public orHaving ( mixed $having ) : self
$having mixed
return self

orWhere() public method

Creates and adds a "or where" to the query.
public orWhere ( mixed $condition, array $params = [] ) : self
$condition mixed
$params array
return self

orWhereExists() public method

Creates and adds a "or where exists" to the query.
public orWhereExists ( Closure $callback, boolean $not = false ) : self
$callback Closure
$not boolean
return self

orWhereIn() public method

Creates and adds a "or where in" to the query.
public orWhereIn ( string $column, mixed $values, boolean $not = false ) : self
$column string
$values mixed
$not boolean
return self

orderBy() public method

Creates and adds an "order by" to the query.
public orderBy ( string $sort, string $order = null ) : self
$sort string
$order string
return self

parameter() protected method

protected parameter ( $name )

params() public method

Get or set multiple query parameters.
public params ( array $params = null ) : array | self
$params array
return array | self

rightJoin() public method

Creates and adds a "right join" to the query.
public rightJoin ( string $table, string $condition = null ) : self
$table string
$condition string
return self

select() public method

Creates and adds a "select" to the query.
public select ( mixed $columns = ['*'] ) : self
$columns mixed
return self

setPart() public method

Sets a query part and replaces all previous values.
public setPart ( string $name, mixed $parts ) : self
$name string
$parts mixed
return self

sum() public method

Execute the query and get the "sum" result.
public sum ( string $column ) : mixed
$column string
return mixed

update() public method

Execute the "update" query with the given values.
public update ( array $values ) : integer
$values array
return integer

where() public method

Creates and adds a "where" to the query.
public where ( mixed $condition, array $params = [] ) : self
$condition mixed
$params array
return self

whereExists() public method

Creates and adds a "where exists" to the query.
public whereExists ( Closure $callback, boolean $not = false, string $type = null ) : self
$callback Closure
$not boolean
$type string
return self

whereIn() public method

Creates and adds a "where in" to the query.
public whereIn ( string $column, mixed $values, boolean $not = false, string $type = null ) : self
$column string
$values mixed
$not boolean
$type string
return self

whereInSet() public method

Creates and adds a "where FIND_IN_SET" equivalent to the query.
public whereInSet ( string $column, mixed $values, boolean $not = false, string $type = null ) : self
$column string
$values mixed
$not boolean
$type string
return self

Property Details

$connection protected_oe property

The Connection.
protected Connection,Pagekit\Database $connection
return Pagekit\Database\Connection

$params protected_oe property

The query parameters.
protected array $params
return array

$parts protected_oe property

The query parts.
protected array $parts
return array