class QueryBuilder

Class QueryBuilder

Properties

protected string $table The database table name.
protected string $primaryKey The primary key column name.
protected wpdb $wpdb The WordPress database object.

Methods

__construct($table, $primaryKey = "id")

No description

all($columns = ['*'])

Retrun a collection of all the records.

get()

Return a collection of records that match the given where conditions.

first()

Return the first record that matches the given where conditions.

last()

Return the last record that matches the given where conditions.

find($id)

Return the record with the given id.

select(array|string $columns = [])

Set the select columns for the query.

array
pluck($column_name)

Return the the values of a single column.

delete()

Delete one or more records.

where(string $column, string $operator = null, mixed $value = null, string $boolean = 'and')

Add a where condition to the query.

orWhere($column, $operator = null, $value = null, $boolean = 'or')

Add an "or where" condition to the query.

whereIn($column, $value, $boolean = 'and')

Add a where IN condition to the query.

orWhereIn($column, $value)

Add a where IN condition to the query.

whereNotIn($column, $value, $boolean = 'and')

Add a where NOT IN condition to the query.

orWhereNotIn($column, $value)

Add a where NOT IN condition to the query.

whereBetween($column, $value, $boolean = 'and')

Add a where BETWEEN condition to the query.

orWhereBetween($column, $value)

Add a where BETWEEN condition to the query.

whereNotBetween($column, $value, $boolean = 'and')

Add a where NOT BETWEEN condition to the query.

orWhereNotBetween($column, $value)

Add a where NOT BETWEEN condition to the query.

orderBy($column, $order = 'asc')

Set the "order by" clause for the query.

offset($value)

Set the offset "limit" clause for the query.

limit($value = 1)

Set the limit "limit" clause for the query.

mixed
value($attribute)

Return a single column's value from the first result of the query.

int
count()

Return the count of the records that match the given where conditions.

int|array
insert(array $values)

Insert one or more records.

update(array $values)

Update one or more records.

truncate()

Truncate the table.

bool
invalidOperatorAndValue(string $operator, mixed $value)

Determine if the given operator and value combination is legal.

void
getTableDescription()

Get the table description.

string
getWordPressTableName($table)

Commodity method to get a WordPress table name.

array
getSQLResults($sql, $type = ARRAY_A)

Execute a wpdb->get_results() query.

mixed
query($sql)

Execute a wpdb->query() query.

mixed
var($sql)

Execute a wpdb->get_var() query.

string
getPrimaryKey()

Return the primary key.

setPrimaryKey($primaryKey)

Set the primary key.

string
getTable()

Return the table name without the prefix.

setTable(string $table)

Set the table name without the prefix.

string
getTableName()

Get the table name with the prefix.

getParentModel()

No description

setParentModel($parentModel)

No description

Details

at line 102
__construct($table, $primaryKey = "id")

Parameters

$table
$primaryKey

at line 137
Collection all($columns = ['*'])

Retrun a collection of all the records.

Parameters

$columns

Return Value

Collection

at line 185
Collection get()

Return a collection of records that match the given where conditions.

Return Value

Collection

at line 195
Model first()

Return the first record that matches the given where conditions.

Return Value

Model

at line 207
Model last()

Return the last record that matches the given where conditions.

Return Value

Model

at line 220
Model find($id)

Return the record with the given id.

Parameters

$id

Return Value

Model

at line 231
select(array|string $columns = [])

Set the select columns for the query.

Parameters

array|string $columns The columns to select.

at line 245
array pluck($column_name)

Return the the values of a single column.

Parameters

$column_name

Return Value

array

at line 260
delete()

Delete one or more records.

at line 280
where(string $column, string $operator = null, mixed $value = null, string $boolean = 'and')

Add a where condition to the query.

Parameters

string $column The column name.
string $operator The operator.
mixed $value The value.
string $boolean The boolean operator.

at line 317
orWhere($column, $operator = null, $value = null, $boolean = 'or')

Add an "or where" condition to the query.

Parameters

$column
$operator
$value
$boolean

at line 357
whereIn($column, $value, $boolean = 'and')

Add a where IN condition to the query.

Parameters

$column
$value
$boolean

at line 372
orWhereIn($column, $value)

Add a where IN condition to the query.

Parameters

$column
$value

at line 383
whereNotIn($column, $value, $boolean = 'and')

Add a where NOT IN condition to the query.

Parameters

$column
$value
$boolean

at line 398
orWhereNotIn($column, $value)

Add a where NOT IN condition to the query.

Parameters

$column
$value

at line 409
whereBetween($column, $value, $boolean = 'and')

Add a where BETWEEN condition to the query.

Parameters

$column
$value
$boolean

at line 424
orWhereBetween($column, $value)

Add a where BETWEEN condition to the query.

Parameters

$column
$value

at line 435
whereNotBetween($column, $value, $boolean = 'and')

Add a where NOT BETWEEN condition to the query.

Parameters

$column
$value
$boolean

at line 450
orWhereNotBetween($column, $value)

Add a where NOT BETWEEN condition to the query.

Parameters

$column
$value

at line 458
orderBy($column, $order = 'asc')

Set the "order by" clause for the query.

Parameters

$column
$order

at line 470
offset($value)

Set the offset "limit" clause for the query.

Parameters

$value

at line 480
limit($value = 1)

Set the limit "limit" clause for the query.

Parameters

$value

at line 492
mixed value($attribute)

Return a single column's value from the first result of the query.

Parameters

$attribute

Return Value

mixed

at line 502
int count()

Return the count of the records that match the given where conditions.

Return Value

int

at line 521
int|array insert(array $values)

Insert one or more records.

Parameters

array $values The data to insert.

Return Value

int|array The inserted id.

at line 551
update(array $values)

Update one or more records.

Parameters

array $values The data to update.

at line 567
truncate()

Truncate the table.

at line 629
protected bool invalidOperatorAndValue(string $operator, mixed $value)

Determine if the given operator and value combination is legal.

Prevents using Null values with invalid operators.

Parameters

string $operator
mixed $value

Return Value

bool

at line 758
protected void getTableDescription()

Get the table description.

Return Value

void

at line 827
protected string getWordPressTableName($table)

Commodity method to get a WordPress table name.

Here we're going to add the prefix to the table name.

Parameters

$table

Return Value

string

at line 845
protected array getSQLResults($sql, $type = ARRAY_A)

Execute a wpdb->get_results() query.

Parameters

$sql
$type

Return Value

array

at line 861
protected mixed query($sql)

Execute a wpdb->query() query.

Parameters

$sql

Return Value

mixed

at line 877
protected mixed var($sql)

Execute a wpdb->get_var() query.

Parameters

$sql

Return Value

mixed

at line 902
string getPrimaryKey()

Return the primary key.

Return Value

string

at line 910
setPrimaryKey($primaryKey)

Set the primary key.

Parameters

$primaryKey

at line 920
string getTable()

Return the table name without the prefix.

Return Value

string

at line 930
setTable(string $table)

Set the table name without the prefix.

Parameters

string $table The table name without the prefix.

at line 940
string getTableName()

Get the table name with the prefix.

Return Value

string

at line 945
getParentModel()

at line 950
setParentModel($parentModel)

Parameters

$parentModel