class SqlBuilder

Builds SQL query.

SqlBuilder is based on great library NotORM http://www.notorm.com written by Jakub Vrana.

Traits

Strict class for better experience.

Properties

protected string $tableName
protected IConventions $conventions
protected string $delimitedTable
protected array $select
protected array $where
protected array $joinCondition
protected array $conditions
protected array $parameters
protected array $order
protected int $limit
protected int $offset
protected string $group
protected string $having
protected array $reservedTableNames
protected array $aliases
protected string $currentAlias

Methods

__construct(string $tableName, Context $context)

No description

string
getTableName()

No description

string
buildInsertQuery()

No description

string
buildUpdateQuery()

No description

string
buildDeleteQuery()

No description

string
getSelectQueryHash(array $columns = null)

Returns select query hash for caching.

string
buildSelectQuery(array $columns = null)

Returns SQL query.

array
getParameters()

No description

void
importConditions(SqlBuilder $builder)

No description

void
addSelect($columns, ...$params)

No description

array
getSelect()

No description

void
resetSelect()

No description

bool
addWhere($condition, ...$params)

No description

bool
addJoinCondition(string $tableChain, $condition, ...$params)

No description

bool
addCondition($condition, array $params, array $conditions, array $conditionsParameters)

No description

array
getConditions()

No description

void
addAlias(string $chain, string $alias)

Adds alias.

void
checkUniqueTableName(string $tableName, string $chain)

No description

void
addOrder($columns, ...$params)

No description

void
setOrder(array $columns, array $parameters)

No description

array
getOrder()

No description

void
setLimit(int|null $limit, int|null $offset)

No description

int|null
getLimit()

No description

int|null
getOffset()

No description

void
setGroup($columns, ...$params)

No description

string
getGroup()

No description

void
setHaving($having, ...$params)

No description

string
getHaving()

No description

string
buildSelect(array $columns)

No description

array
parseJoinConditions($joins, $joinConditions)

No description

void
getSortedJoins(string $table, $leftJoinDependency, $tableJoins, $finalJoins)

No description

void
parseJoins($joins, $query)

No description

string
parseJoinsCb($joins, $match)

No description

string
buildQueryJoins(array $joins, array $leftJoinConditions = [])

No description

array
buildJoinConditions()

No description

string
buildConditions()

No description

string
buildQueryEnd()

No description

string
tryDelimite(string $s)

No description

bool
addConditionComposition(array $columns, array $parameters, array $conditions, array $conditionsParameters)

No description

Details

at line 96
__construct(string $tableName, Context $context)

Parameters

string $tableName
Context $context

at line 108
string getTableName()

Return Value

string

at line 114
string buildInsertQuery()

Return Value

string

at line 120
string buildUpdateQuery()

Return Value

string

at line 136
string buildDeleteQuery()

Return Value

string

at line 150
string getSelectQueryHash(array $columns = null)

Returns select query hash for caching.

Parameters

array $columns

Return Value

string

at line 183
string buildSelectQuery(array $columns = null)

Returns SQL query.

Parameters

array $columns

Return Value

string

at line 231
array getParameters()

Return Value

array

at line 247
void importConditions(SqlBuilder $builder)

Parameters

SqlBuilder $builder

Return Value

void

at line 262
void addSelect($columns, ...$params)

Parameters

$columns
...$params

Return Value

void

at line 272
array getSelect()

Return Value

array

at line 278
void resetSelect()

Return Value

void

at line 285
bool addWhere($condition, ...$params)

Parameters

$condition
...$params

Return Value

bool

at line 291
bool addJoinCondition(string $tableChain, $condition, ...$params)

Parameters

string $tableChain
$condition
...$params

Return Value

bool

at line 301
protected bool addCondition($condition, array $params, array $conditions, array $conditionsParameters)

Parameters

$condition
array $params
array $conditions
array $conditionsParameters

Return Value

bool

at line 421
array getConditions()

Return Value

array

at line 430
void addAlias(string $chain, string $alias)

Adds alias.

Parameters

string $chain
string $alias

Return Value

void

at line 440
protected void checkUniqueTableName(string $tableName, string $chain)

Parameters

string $tableName
string $chain

Return Value

void

at line 455
void addOrder($columns, ...$params)

Parameters

$columns
...$params

Return Value

void

at line 462
void setOrder(array $columns, array $parameters)

Parameters

array $columns
array $parameters

Return Value

void

at line 469
array getOrder()

Return Value

array

at line 475
void setLimit(int|null $limit, int|null $offset)

Parameters

int|null $limit
int|null $offset

Return Value

void

at line 482
int|null getLimit()

Return Value

int|null

at line 488
int|null getOffset()

Return Value

int|null

at line 494
void setGroup($columns, ...$params)

Parameters

$columns
...$params

Return Value

void

at line 501
string getGroup()

Return Value

string

at line 507
void setHaving($having, ...$params)

Parameters

$having
...$params

Return Value

void

at line 514
string getHaving()

Return Value

string

at line 523
protected string buildSelect(array $columns)

Parameters

array $columns

Return Value

string

at line 529
protected array parseJoinConditions($joins, $joinConditions)

Parameters

$joins
$joinConditions

Return Value

array

at line 562
protected void getSortedJoins(string $table, $leftJoinDependency, $tableJoins, $finalJoins)

Parameters

string $table
$leftJoinDependency
$tableJoins
$finalJoins

Return Value

void

at line 596
protected void parseJoins($joins, $query)

Parameters

$joins
$query

Return Value

void

at line 612
string parseJoinsCb($joins, $match)

Parameters

$joins
$match

Return Value

string

at line 715
protected string buildQueryJoins(array $joins, array $leftJoinConditions = [])

Parameters

array $joins
array $leftJoinConditions

Return Value

string

at line 728
protected array buildJoinConditions()

Return Value

array

at line 738
protected string buildConditions()

Return Value

string

at line 744
protected string buildQueryEnd()

Return Value

string

at line 760
protected string tryDelimite(string $s)

Parameters

string $s

Return Value

string

at line 768
protected bool addConditionComposition(array $columns, array $parameters, array $conditions, array $conditionsParameters)

Parameters

array $columns
array $parameters
array $conditions
array $conditionsParameters

Return Value

bool