PHP Class LessQL\Result

SELECT {* | select_expr, ...} FROM table [WHERE condition [AND condition [...]]] [ORDER BY {col_name | expr | position} [ASC | DESC], ...] [LIMIT count [OFFSET offset]] TODO Add more SQL dialect specifics like FETCH FIRST, TOP etc.
Inheritance: implements IteratorAggregate, implements JsonSerializable
Show file Open project: morris/lessql

Protected Properties

Property Type Description
$_cache array
$db Database
$globalRows null | lessql\Row[]
$key null | string
$limitCount null | integer
$limitOffset null | integer
$orderBy array
$parentKey null | string
$parent_ null | Result | lessql\Row
$rows null | lessql\Row[]
$select null | string
$single null | boolean
$table string
$where array
$whereParams array

Public Methods

Method Description
__call ( string $name, array $args ) : mixed Get referenced row(s) by name. Suffix "List" gets many rows Arguments are passed to where( $where, $params )
__clone ( )
__construct ( Database | Result | lessql\Row $parent, string $name ) Constructor Use $db->createResult( $parent, $name ) instead
aggregate ( string $function ) : mixed Execute aggregate function and return value
count ( string $expr = "*" ) : integer Count number of rows Implements Countable
createRow ( array $data = [] ) : lessql\Row Create a Row for this result's table The row is bound to this result
delete ( ) : PDOStatement Delete all rows matched by this result
execute ( ) Execute the select query defined by this result.
fetch ( ) : lessql\Row Fetch the next row in this result
fetchAll ( ) : lessql\Row[] Fetch all rows in this result
getCache ( string $key ) : null | mixed Get value from cache
getDatabase ( ) : Database Get the database
getDefinition ( ) : string Get a JSON string defining the SELECT information of this Result Used as identification in caches
getGlobalKeys ( string $key ) : array Get global $key values of the result, i.e., disregarding its parent
getIterator ( ) : ArrayIterator IteratorAggregate
getLocalKeys ( string $key ) : array Get $key values of this result
getParent ( ) : Result | lessql\Row Get parent result or row, if any
getRoot ( ) : Result Get the root result
getTable ( ) : string Get the table of this result
insert ( array $rows, string | null $method = null ) : null | PDOStatement Insert one ore more rows into the table of this result See Database::insert for information on $method
isSingle ( ) : boolean Is this result a single association, i.e. not a list of rows?
jsonSerialize ( ) : lessql\Row[] Implements JsonSerialize
limit ( integer $count, integer | null $offset = null ) Set a result limit and optionally an offset
max ( string $expr ) : string Return maximum value from an expression
min ( string $expr ) : string Return minimum value from an expression
orderBy ( string $column, string $direction = "ASC" ) Add an ORDER BY column and direction
paged ( integer $pageSize, integer $page ) Set a paged limit Pages start at 1
primaryResult ( ) : Result Return a new basic result which selects all rows in this result by primary key
referenced ( string $name, string | array | null $where = null, array $params = [] ) : Result Get referenced row(s) by name. Suffix "List" gets many rows
rowCount ( ) : integer Return number of rows in this result
select ( string $expr ) : Result Return a new result with an additional expression to the SELECT part
setCache ( string $key, mixed $value ) Set cache value
sum ( string $expr ) : string Return sum of values in an expression
update ( array $data ) : null | PDOStatement Update the rows matched by this result, setting $data
via ( string $key ) : Result Create result with new reference key
where ( string | array $condition, string | array $params = [] ) : Result Add a WHERE condition (multiple are combined with AND)
whereNot ( string | array $column, string | array | null $value = null ) Add a "$column is not $value" condition to WHERE (multiple are combined with AND)

Protected Methods

Method Description
getKeys ( lessql\Row[] $rows, string $key ) : array Get $key values of given rows

Method Details

__call() public method

Get referenced row(s) by name. Suffix "List" gets many rows Arguments are passed to where( $where, $params )
public __call ( string $name, array $args ) : mixed
$name string
$args array
return mixed

__clone() public method

public __clone ( )

__construct() public method

Constructor Use $db->createResult( $parent, $name ) instead
public __construct ( Database | Result | lessql\Row $parent, string $name )
$parent Database | Result | lessql\Row
$name string

aggregate() public method

Execute aggregate function and return value
public aggregate ( string $function ) : mixed
$function string
return mixed

count() public method

Count number of rows Implements Countable
public count ( string $expr = "*" ) : integer
$expr string
return integer

createRow() public method

Create a Row for this result's table The row is bound to this result
public createRow ( array $data = [] ) : lessql\Row
$data array Row data
return lessql\Row

delete() public method

Delete all rows matched by this result
public delete ( ) : PDOStatement
return PDOStatement

execute() public method

Execute the select query defined by this result.
public execute ( )

fetch() public method

Fetch the next row in this result
public fetch ( ) : lessql\Row
return lessql\Row

fetchAll() public method

Fetch all rows in this result
public fetchAll ( ) : lessql\Row[]
return lessql\Row[]

getCache() public method

Get value from cache
public getCache ( string $key ) : null | mixed
$key string
return null | mixed

getDatabase() public method

Get the database
public getDatabase ( ) : Database
return Database

getDefinition() public method

Get a JSON string defining the SELECT information of this Result Used as identification in caches
public getDefinition ( ) : string
return string

getGlobalKeys() public method

Get global $key values of the result, i.e., disregarding its parent
public getGlobalKeys ( string $key ) : array
$key string
return array

getIterator() public method

IteratorAggregate

getKeys() protected method

Get $key values of given rows
protected getKeys ( lessql\Row[] $rows, string $key ) : array
$rows lessql\Row[]
$key string
return array

getLocalKeys() public method

Get $key values of this result
public getLocalKeys ( string $key ) : array
$key string
return array

getParent() public method

Get parent result or row, if any
public getParent ( ) : Result | lessql\Row
return Result | lessql\Row

getRoot() public method

Get the root result
public getRoot ( ) : Result
return Result

getTable() public method

Get the table of this result
public getTable ( ) : string
return string

insert() public method

Insert one ore more rows into the table of this result See Database::insert for information on $method
public insert ( array $rows, string | null $method = null ) : null | PDOStatement
$rows array
$method string | null
return null | PDOStatement

isSingle() public method

Is this result a single association, i.e. not a list of rows?
public isSingle ( ) : boolean
return boolean

jsonSerialize() public method

Implements JsonSerialize
public jsonSerialize ( ) : lessql\Row[]
return lessql\Row[]

limit() public method

Set a result limit and optionally an offset
public limit ( integer $count, integer | null $offset = null )
$count integer
$offset integer | null

max() public method

Return maximum value from an expression
public max ( string $expr ) : string
$expr string
return string

min() public method

Return minimum value from an expression
public min ( string $expr ) : string
$expr string
return string

orderBy() public method

Add an ORDER BY column and direction
public orderBy ( string $column, string $direction = "ASC" )
$column string
$direction string

paged() public method

Set a paged limit Pages start at 1
public paged ( integer $pageSize, integer $page )
$pageSize integer
$page integer

primaryResult() public method

Return a new basic result which selects all rows in this result by primary key
public primaryResult ( ) : Result
return Result

referenced() public method

Get referenced row(s) by name. Suffix "List" gets many rows
public referenced ( string $name, string | array | null $where = null, array $params = [] ) : Result
$name string
$where string | array | null
$params array
return Result

rowCount() public method

Return number of rows in this result
public rowCount ( ) : integer
return integer

select() public method

Return a new result with an additional expression to the SELECT part
public select ( string $expr ) : Result
$expr string
return Result

setCache() public method

Set cache value
public setCache ( string $key, mixed $value )
$key string
$value mixed

sum() public method

Return sum of values in an expression
public sum ( string $expr ) : string
$expr string
return string

update() public method

Update the rows matched by this result, setting $data
public update ( array $data ) : null | PDOStatement
$data array
return null | PDOStatement

via() public method

Create result with new reference key
public via ( string $key ) : Result
$key string
return Result

where() public method

Add a WHERE condition (multiple are combined with AND)
public where ( string | array $condition, string | array $params = [] ) : Result
$condition string | array
$params string | array
return Result

whereNot() public method

Add a "$column is not $value" condition to WHERE (multiple are combined with AND)
public whereNot ( string | array $column, string | array | null $value = null )
$column string | array
$value string | array | null

Property Details

$_cache protected property

protected array $_cache
return array

$db protected property

protected Database,lessql $db
return Database

$globalRows protected property

protected null|Row[],lessql $globalRows
return null | lessql\Row[]

$key protected property

protected null|string $key
return null | string

$limitCount protected property

protected null|int $limitCount
return null | integer

$limitOffset protected property

protected null|int $limitOffset
return null | integer

$orderBy protected property

protected array $orderBy
return array

$parentKey protected property

protected null|string $parentKey
return null | string

$parent_ protected property

protected null|Result,lessql|Row,lessql $parent_
return null | Result | lessql\Row

$rows protected property

protected null|Row[],lessql $rows
return null | lessql\Row[]

$select protected property

protected null|string $select
return null | string

$single protected property

protected null|bool $single
return null | boolean

$table protected property

protected string $table
return string

$where protected property

protected array $where
return array

$whereParams protected property

protected array $whereParams
return array