class Select extends Command implements SelectInterface (View source)

Constants

RETURN_COUNT

These are the valid return types for commands

RETURN_BEFORE

RETURN_AFTER

Properties

protected $ridValidator from Command
protected $escapeValidator from Command
protected $formatter from Command
protected $formatters from Command
protected $tokens from Command

Methods

__construct(array $target = null)

Builds a Select object injecting the $target into the FROM clause.

getSchema()

No description

andWhere(string $condition, string $value = null)

Sets a where token using the AND operator.

from Command
from(array $target, boolean $append = true)

Sets the token for the from clause. You can $append your values.

from Command
string
getRaw()

Returns the raw SQL query incapsulated by the current object.

from Command
array
getTokens()

Analyzing the command's SCHEMA, this method returns all the tokens allocable in the command.

from Command
array
getTokenValue(string $token)

Returns the value of a token.

from Command
orWhere(string $condition, string $value = null)

Sets a where token using the OR operator.

from Command
true
resetWhere()

Deletes all the WHERE and BETWEEN conditions in the current SELECT.

setFormatter(QueryInterface $formatter)

Sets the internal query formatter object.

from Command
where(string $condition, mixed $value = null, boolean $append = false, string $clause = "WHERE")

Adds a WHERE conditions into the current query.

from Command
boolean
canHydrate()

Returns whether this query, when executed, should have the collection hydrated.

from Command
returns($returns)

Sets the Returns token

from Command
array()
getValidReturnTypes()

Returns the array of valid params for the Return clause.

from Command
appendToken(string $token, mixed $values, boolean $first = false)

Appends a token to the query, without deleting existing values for the given $token.

from Command
appendTokenAsString(string $token, string $key, mixed $value)

Appends $value to the query $token, using $key to identify the $value in the token array.

from Command
appendTokenAsInteger(string $token, string $key, mixed $value)

Appends $value to the query $token.

from Command
mixed
checkToken(string $token)

Checks if a token is set, returning it if it is.

from Command
clearToken(string $token)

Clears the value of a token.

from Command
getFormatter()

Returns a brand new instance of a Formatter in order to format query tokens.

from Command
Array
getTokenFormatters()

Returns the formatters for this query tokens

Array
getTokenFormatter(string $token)

Returns the formatter for a particular token.

from Command
array
getTokenReplaces()

Returns the values to replace command's schema tokens.

from Command
string
getValidStatement()

Build the command replacing schema tokens with actual values and cleaning the command synthax.

from Command
string
formatWhereConditionWithMultipleTokens($condition, array $values, Escaper $validator)

Substitutes multiple tokens ($values) in the WHERE $condition.

from Command
string
replaceTokens(string $statement)

Replaces the tokens in the command's schema with their actual values in the current object.

from Command
true
setToken(string $token, string $tokenValue, boolean $append = false, boolean $first = false)

Sets a single value for a token,

from Command
true
setTokenValues($token, array $tokenValues, $append = true, $first = false)

Sets the values of a token, and can be appended with the given $append.

from Command
unsetToken(string $token)

Deletes a token.

from Command
string
tokenize(string $token)

Tokenizes a string.

from Command
between(string $key, string $left, string $right)

Converts the "normal" select into an index one.

select(array $projections, boolean $append = true)

Sets the fields to select.

orderBy(string $order, boolean $append = true, boolean $first = false)

Orders the query.

limit(integet $limit)

Sets a limit to the SELECT.

skip($records)

Sets the number of records to skip.

Details

__construct(array $target = null)

Builds a Select object injecting the $target into the FROM clause.

Parameters

array $target

protected getSchema()

Command andWhere(string $condition, string $value = null)

Sets a where token using the AND operator.

If the $condition contains a "?", it will be replaced by the $value.

Parameters

string $condition
string $value

Return Value

Command

Command from(array $target, boolean $append = true)

Sets the token for the from clause. You can $append your values.

Parameters

array $target
boolean $append

Return Value

Command

string getRaw()

Returns the raw SQL query incapsulated by the current object.

Return Value

string

array getTokens()

Analyzing the command's SCHEMA, this method returns all the tokens allocable in the command.

Return Value

array

array getTokenValue(string $token)

Returns the value of a token.

Parameters

string $token

Return Value

array

Command orWhere(string $condition, string $value = null)

Sets a where token using the OR operator.

If the $condition contains a "?", it will be replaced by the $value.

Parameters

string $condition
string $value

Return Value

Command

true resetWhere()

Deletes all the WHERE and BETWEEN conditions in the current SELECT.

Return Value

true

setFormatter(QueryInterface $formatter)

Sets the internal query formatter object.

Parameters

QueryInterface $formatter

where(string $condition, mixed $value = null, boolean $append = false, string $clause = "WHERE")

Adds a WHERE conditions into the current query.

Parameters

string $condition
mixed $value
boolean $append
string $clause

boolean canHydrate()

Returns whether this query, when executed, should have the collection hydrated.

The default is true

Return Value

boolean

returns($returns)

Sets the Returns token

Parameters

$returns

array() getValidReturnTypes()

Returns the array of valid params for the Return clause.

Use this function to support the Return clause by overriding and returing a list in the subclass

Return Value

array()

protected appendToken(string $token, mixed $values, boolean $first = false)

Appends a token to the query, without deleting existing values for the given $token.

Parameters

string $token
mixed $values
boolean $first

protected appendTokenAsString(string $token, string $key, mixed $value)

Appends $value to the query $token, using $key to identify the $value in the token array.

With this method you set a token value and can retrieve it by its key.

Parameters

string $token
string $key
mixed $value

protected appendTokenAsInteger(string $token, string $key, mixed $value)

Appends $value to the query $token.

Parameters

string $token
string $key
mixed $value

protected mixed checkToken(string $token)

Checks if a token is set, returning it if it is.

Parameters

string $token

Return Value

mixed

Exceptions

TokenNotFoundException

protected clearToken(string $token)

Clears the value of a token.

Parameters

string $token

protected QueryInterface getFormatter()

Returns a brand new instance of a Formatter in order to format query tokens.

Return Value

QueryInterface

protected Array getTokenFormatters()

Returns the formatters for this query tokens

Return Value

Array

protected Array getTokenFormatter(string $token)

Returns the formatter for a particular token.

Parameters

string $token

Return Value

Array

Exceptions

string

protected array getTokenReplaces()

Returns the values to replace command's schema tokens.

Return Value

array

protected string getValidStatement()

Build the command replacing schema tokens with actual values and cleaning the command synthax.

Return Value

string

protected string formatWhereConditionWithMultipleTokens($condition, array $values, Escaper $validator)

Substitutes multiple tokens ($values) in the WHERE $condition.

Parameters

$condition
array $values
Escaper $validator

Return Value

string

Exceptions

LogicException

protected string replaceTokens(string $statement)

Replaces the tokens in the command's schema with their actual values in the current object.

Parameters

string $statement

Return Value

string

true setToken(string $token, string $tokenValue, boolean $append = false, boolean $first = false)

Sets a single value for a token,

Parameters

string $token
string $tokenValue
boolean $append
boolean $first

Return Value

true

protected true setTokenValues($token, array $tokenValues, $append = true, $first = false)

Sets the values of a token, and can be appended with the given $append.

Parameters

$token
array $tokenValues
$append
$first

Return Value

true

protected unsetToken(string $token)

Deletes a token.

Parameters

string $token

protected string tokenize(string $token)

Tokenizes a string.

Parameters

string $token

Return Value

string

Select between(string $key, string $left, string $right)

Converts the "normal" select into an index one.

Index selects can query with the BETWEEN operator: select from index:name where x between 10.3 and 10.7

Parameters

string $key
string $left
string $right

Return Value

Select

Select select(array $projections, boolean $append = true)

Sets the fields to select.

Parameters

array $projections
boolean $append

Return Value

Select

Select orderBy(string $order, boolean $append = true, boolean $first = false)

Orders the query.

Parameters

string $order
boolean $append
boolean $first

Return Value

Select

Select limit(integet $limit)

Sets a limit to the SELECT.

Parameters

integet $limit

Return Value

Select

skip($records)

Sets the number of records to skip.

Parameters

$records