Properties

$table

$table : string

Type

string — The SQL Table associated with this model.

$ids

$ids : string|array

Type

string|array — The SQL primary key or composite key associated with this model.

$alias

$alias : string|null

Type

string|null — An alias to apply to the model when making queries.

$aliasWasSet

$aliasWasSet : boolean

Type

boolean — Was the alias set by method call?

$lastQuery

$lastQuery : string

Type

string — The last query this model executed.

$select

$select : string

Type

string — The working select statement.

$update

$update : string

Type

string — The working update statement.

$where

$where : string

Type

string — The where condition or the working query.

$joinOn

$joinOn : array

Type

array — The tables we should join on with the working query.

$limit

$limit : array

Type

array — The limit and potential limit offset to apply to the working query.

$order

$order : array

Type

array — The ordering of the working query.

Methods

clearData()

clearData() : void

Reset our model conditions.

alias()

alias(string  $alias) : self

Alias the table name of the model. Use when performing joins.

Parameters

string $alias

The alias.

Returns

self

select()

select() : self

Prepare a SELECT condition.

Accepts its arguements through func_get_args().

Returns

self

update()

update() : self

Prepare an UPDATE statement.

Uses func_get_args() to accept parameters.

Returns

self

finalize()

finalize() : boolean

Execute the UPDATE statement that was previously prepared.

Returns

boolean —

Return whether the update was successful.

commit()

commit() 

Alias of `$this->finalize()`.

insert()

insert() : boolean

Execute an INSERT statement.

Accepts its arguements through func_get_args().

Returns

boolean —

Was the insert successful?

delete()

delete() : boolean

Execute a DELETE statement.

Accepts its arguements thruogh func_get_args().

Delete records where all the key/value pairs match.

Returns

boolean —

Whether or not the delete was successful.

deleteOr()

deleteOr() : boolean

Execute a DELETE statement.

Accepts its arguements thruogh func_get_args().

Will delete any records that match any of the key/values pairs.

Returns

boolean —

Whether or not the delete was successful.

deleteIn()

deleteIn(string  $field, string|array  $array) : self

Prepare a DELETE condition for the query.

Delete records where a value is in the key/value pairs.

Parameters

string $field

The field to look in.

string|array $array

A string of comma seperated values, or an array of values.

Returns

self

where()

where() : self

Specify a WHERE condition for the working query.

Accepts its arguements through func_get_args().

Will find records where all key/value pairs match.

Returns

self

whereOr()

whereOr() : self

Specify a WHERE condition for the working query.

Accepts its arguements through func_get_args().

Will find records where any of the key/value pairs match.

Returns

self

whereNotOr()

whereNotOr() : self

Specify a WHERE condition for the working query.

Accepts its arguements through func_get_args().

Will find records where key/values pairs do not match any conditions.

Returns

self

whereAlso()

whereAlso() : self

Specify a WHERE condition for the working query.

Accepts its arguements through func_get_args().

Starts a new condition group by wrapping the previous condition in paranethesis and starting the new condition group with an AND. Then in the new condition group match records where all of the key/value pairs match.

Returns

self

whereNot()

whereNot() : self

Specify a WHERE condition for the working query.

Accepts its arguements through func_get_args().

Find record where none of the values match the key/value pairs.

Returns

self

whereNotAlso()

whereNotAlso() : self

Prepare the WHERE condition for the working query.

Accepts its arguements through func_get_args().

Starts a new condition group by wrapping the previous condition in paranethesis and starting the new condition group with an AND. Then in the new condition group match records where none of the key/value pairs match.

Returns

self

whereLike()

whereLike() : self

Prepare the WHERE condition for the working query.

Accepts its arguements through func_get_args().

Find records that are like the key/value pairs. AKA a regexp.

Returns

self

whereAlsoLike()

whereAlsoLike() : self

Prepare the WHERE condition for the working query.

Accepts its arguements through func_get_args().

Starts a new condition group by wrapping the previous condition in paranethesis and starting the new condition group with an AND. Then in the new condition group match records that are like the key/value pairs.

Returns

self

whereNotLike()

whereNotLike() : self

Prepare the WHERE condition for the working query.

Accepts its arguements through func_get_args().

Find records that are not like the key/value pairs.

Returns

self

whereNotAlsoLike()

whereNotAlsoLike() : self

Prepare the WHERE condition for the working query.

Accepts its arguements through func_get_args().

Starts a new condition group by wrapping the previous condition in paranethesis and starting the new condition group with an AND. Then in the new condition group match records that are not like the key/value pairs.

Returns

self

whereIn()

whereIn(string  $field, string|array  $array) : self

Prepare a WHERE condition for the query.

Find records where a value is in the key/value pairs.

Parameters

string $field

The field to look in.

string|array $array

A string of comma seperated values, or an array of values.

Returns

self

whereNotIn()

whereNotIn(string  $field, string|array  $array) : self

Prepare a WHERE IN condition for the query.

Find records where a value is not in the key/value pairs.

Parameters

string $field

The field to look in.

string|array $array

A string of comma seperated values, or an array of values.

Returns

self

whereOrIn()

whereOrIn(string  $field, string|array  $array) : self

Prepare a WHERE IN condition for the query.

Find records where a value is in the key/value pairs.

Parameters

string $field

The field to look in.

string|array $array

A string of comma seperated values, or an array of values.

Returns

self

whereOrNotIn()

whereOrNotIn(string  $field, string|array  $array) : self

Prepare a WHERE IN condition for the query.

Find records where a value is not in the key/value pairs.

Parameters

string $field

The field to look in.

string|array $array

A string of comma seperated values, or an array of values.

Returns

self

orWhere()

orWhere() : self

Prepare the WHERE condition for the working query.

Accepts its arguements through func_get_args().

Find records where the key/value pairs match.

Returns

self

orWhereOr()

orWhereOr() : self

Prepare the WHERE condition for the working query.

Accepts its arguements through func_get_args().

Find records where any of the key/value pairs match.

Returns

self

otherwise()

otherwise() 

Alias of `$this->orWhereOr()`.

orWhereNotOr()

orWhereNotOr() : self

Prepare the WHERE condition for the working query.

Accepts its arguements through func_get_args().

Will find records where key/values pairs do not match any conditions.

Returns

self

orWhereNot()

orWhereNot() : self

Prepare the WHERE condition for the working query.

Accepts its arguements through func_get_args().

Find record where none of the values match the key/value pairs.

Returns

self

orWhereLike()

orWhereLike() : self

Prepare the WHERE condition for the working query.

Accepts its arguements through func_get_args().

Find records that are like the key/value pairs. AKA a regexp.

Returns

self

orWhereNotLike()

orWhereNotLike() : self

Prepare the WHERE condition for the working query.

Accepts its arguements through func_get_args().

Find records that are not like the key/value pairs.

Returns

self

orWhereIn()

orWhereIn(string  $field, string|array  $array) : self

Prepare a WHERE IN condition for the query.

Find records where a value is in the key/value pairs.

Parameters

string $field

The field to look in.

string|array $array

A string of comma seperated values, or an array of values.

Returns

self

orWhereNotIn()

orWhereNotIn(string  $field, string|array  $array) : self

Prepare a WHERE IN condition for the query.

Find records where a value is not in the key/value pairs.

Parameters

string $field

The field to look in.

string|array $array

A string of comma seperated values, or an array of values.

Returns

self

join()

join(string  $modelName, string|array  $on = null, mixed  $data = null,   $joinType = 'INNER JOIN') : self

Prepare the JOIN condition for the working SELECT query.

To join through the ORM you must have a defined Model which extends BaseModel and has its $table and $ids values set as this will be used to execute the join on.

Parameters

string $modelName

The name of the Model you will join on.

string|array $on

The condition used to join on.

mixed $data

Data that should be bound into the $on condition.

$joinType

Returns

self

ljoin()

ljoin(string  $modelName, string|array  $on = null, mixed  $data = null) : self

Read docs on join function first, this simply extends that function and passes in a LEFT JOIN as the second arguement.

Parameters

string $modelName

The name of the Model you will join on.

string|array $on

The condition used to join on.

mixed $data

Data that should be bound into the $on condition.

Returns

self

rjoin()

rjoin(string  $modelName, string|array  $on = null, mixed  $data = null) : self

Read docs on join function first, this simply extends that function and passes in a RIGHT JOIN as the second arguement.

Parameters

string $modelName

The name of the Model you will join on.

string|array $on

The condition used to join on.

mixed $data

Data that should be bound into the $on condition.

Returns

self

order()

order() : self

Set an ORDER BY condition for the current SELECT query.

Accepts its parameters through func_get_args(). Takes strings and numbers.

Returns

self

limit()

limit(integer  $start, null|integer  $limit = null) : self

Set a LIMIT condition on the current SELECT query.

Parameters

integer $start

Starting position of LIMIT or the number of tuples to return contigent upon the exsistance of the second parameter $limit.

null|integer $limit

The number of tuples to return.

Returns

self

getLimit()

getLimit() : array

Get the current limit being prepared for the active query. This method really only exists to be used with the twig `page` tag.

Returns

array

data()

data() : mixed

Return the data from the execution of the previous query.

Returns

mixed —

Result of last query.

asArray()

asArray() : array

Return the data from the execution of the previous query.

Returns

array

first()

first() : array

Get the first row of the query.

Returns

array —

The first row

compile()

compile() : string

Compile the select query from the conditions.

Returns

string —

The compiled raw query.

prepareCondition()

prepareCondition(array  $data, string  $conjunction, string  $comparator = '=') : mixed

Prepare a condition to be used in the query.

For example $data contains:

  • 'price'
  • '>'
  • 59.99

    We want to make this a DML statement like:

  • tablename.price>59.99

    But we also will likely have another condition that will precede the first one we are passed, that is where the $conjuction paramater comes into play. Its value will be a literal conjuction such as 'AND' or 'OR' or ','

This function uses the DB method set() to safely bind the passed variables into the DML statement.

Parameters

array $data

Pieces of the condition that needs to be prepared.

string $conjunction

The conjuction to be used if more than one condition is present.

string $comparator

The comparator used to form the comparison condition between the key and the value.

Returns

mixed —

$where Either return the condition or false if there was no condition to prepare.

about()

about() : Array

Get schema information about the table.

Returns

Array

columns()

columns() : Array

Get column information about the table.

Returns

Array

buildWhereInArray()

buildWhereInArray(array  $array) : string

Get a commas delimited string of values for use in an IN query.

Parameters

array $array

The array of values.

Returns

string

buildWhere()

buildWhere() : string

Build the final where condition to be used in the query statement.

Returns

string

fieldAlias()

fieldAlias(string  $k) : string

Return an aliased field name.

Parameters

string $k

The field name to alias.

Returns

string

tableAlias()

tableAlias() : string

Return an aliased table name.

Returns

string

executeQuery()

executeQuery(string  $query) : array

Wrapper thats calls the DB service `query` method. Sets `$this->lastQuery` to the passed param. It also clears the data on the object to clean its state for a new method chain/query.

Parameters

string $query

The query to execute.

Returns

array