Documentation

PdbQuery
in package
implements PdbQueryInterface, ArrayableInterface, JsonSerializable, ConfigurableInterface

Query elements: - `select(...$fields)` - `andSelect(...$fields)` - `from($table, [$alias])` - `alias($alias)` - `leftJoin($table, $conditions, $combine)` - `innerJoin($table, $conditions, $combine)` - `where($conditions, $combine)` - `andWhere($conditions, $combine)` - `orWhere($conditions, $combine)` - `with($subQuery, $alias)` - `union($subQuery)` - `groupBy($field)` - `orderBy(...$fields)` - `limit($limit)` - `offset($limit)`

Shorthands:

  • find($table, $conditions)

Modifiers:

  • as($class)
  • throw($bool)
  • cache($ttl)
  • indexBy($field)

Terminator methods:

  • build(): [string, array]
  • value($field): string
  • one($throw): array|object
  • all(): array
  • map($key, $value): array
  • keyed($key): array
  • column(): array
  • count(): int
  • exists(): bool
  • iterator(): iterable
  • batch($size): iterable<array>
  • pdo(): PDO
  • execute(): mixed

Class builders:

  • one(): object
  • all(): object[]
  • keyed(): [key => object]
  • iterator(): iterable<object>
  • batch($size): iterable<object[]>
  • each($size): iterable<object>

Table of Contents

Interfaces

PdbQueryInterface
ArrayableInterface
This object can be explicitly converted to an array with a `toArray()` method.
JsonSerializable
ConfigurableInterface
This class is 'configurable' - it has an `update()` method that accepts iterables.

Properties

$_as  : string|null
$_cache_key  : string|null
Override the cache key.
$_cache_ttl  : int|bool
- true: use `pdb.config.ttl` - false: no cache (default) - int: cache for this many seconds
$_from  : PdbQueryInterface, 1: string|null}|null
single [field, alias]
$_group  : array<string|int, string>
$_having  : array<string|int, PdbConditionInterface, 2: string}>
list [type, conditions, combine]
$_joins  : array<string|int, PdbConditionInterface, 3: string}>
list [ type, [table, alias], conditions, combine ]
$_keyed  : string|null
$_limit  : int
$_offset  : int
$_order  : array<string|int, mixed>
$_select  : array<string|int, mixed>
$_throw  : bool
$_union  : array<string|int, PdbQueryInterface>
$_where  : array<string|int, PdbConditionInterface, 2: string}>
list [type, conditions, combine]
$_with  : array<string|int, PdbQueryInterface, 1: string}>
list [query, alias]
$pdb  : Pdb

Methods

__construct()  : mixed
alias()  : static
Set the alias for the FROM table.
all()  : array<string|int, mixed>
andSelect()  : static
Select more things.
andWhere()  : static
as()  : static
batch()  : Generator<string|int, array<string|int, mixed>>
build()  : array<string|int, mixed>
cache()  : static
clone()  : static
Get a copy of this query.
column()  : array<string|int, mixed>
count()  : int
each()  : Generator
execute()  : mixed
exists()  : bool
find()  : static
from()  : static
Set the FROM table and alias (optional).
getAlias()  : string
Get the query table alias.
getIdentifiers()  : array<string|int, string|PdbQueryInterface>
getReturnConfig()  : PdbReturnInterface
group()  : static
groupBy()  : static
having()  : static
indexBy()  : static
Specify a key for array results.
innerJoin()  : static
iterator()  : Generator
join()  : static
jsonSerialize()  : array<string|int, mixed>
keyed()  : array<string|int, mixed>
This ends a query.
leftJoin()  : static
limit()  : static
map()  : array<string|int, mixed>
offset()  : static
one()  : array<string|int, mixed>|object|null
order()  : static
orderBy()  : static
orWhere()  : static
pdo()  : PDOStatement
select()  : static
Select a list of fields.
throw()  : static
Emit RowMissingExceptions if the record is not found.
toArray()  : array<string|int, mixed>
Convert this object to an array.
union()  : static
Add a sub-query to the UNION clause.
update()  : void
Update the object with a new configuration.
validate()  : void
value()  : string|null
where()  : static
with()  : static
Add a sub-query to the WITH clause.
_afterBuild()  : void
_beforeBuild()  : void
_build()  : array<string|int, mixed>
_join()  : static

Properties

$_cache_key

Override the cache key.

protected string|null $_cache_key = null

$_cache_ttl

- true: use `pdb.config.ttl` - false: no cache (default) - int: cache for this many seconds

protected int|bool $_cache_ttl = false

$_from

single [field, alias]

protected PdbQueryInterface, 1: string|null}|null $_from = null

$_group

protected array<string|int, string> $_group = []

$_having

list [type, conditions, combine]

protected array<string|int, PdbConditionInterface, 2: string}> $_having = []

$_joins

list [ type, [table, alias], conditions, combine ]

protected array<string|int, PdbConditionInterface, 3: string}> $_joins = []

$_keyed

protected string|null $_keyed = null

$_order

protected array<string|int, mixed> $_order = []

list [field, order]

$_select

protected array<string|int, mixed> $_select = []

list [field, alias]

$_where

list [type, conditions, combine]

protected array<string|int, PdbConditionInterface, 2: string}> $_where = []

$_with

list [query, alias]

protected array<string|int, PdbQueryInterface, 1: string}> $_with = []

Methods

__construct()

public __construct(Pdb|PdbConfig|array<string|int, mixed> $pdb[, array<string|int, mixed> $config = [] ]) : mixed
Parameters
$pdb : Pdb|PdbConfig|array<string|int, mixed>
$config : array<string|int, mixed> = []

alias()

Set the alias for the FROM table.

public alias(string $alias) : static

This can only modify an existing FROM statement.

Parameters
$alias : string
Tags
throws
InvalidArgumentException
Return values
static

andSelect()

Select more things.

public andSelect(string|array<string|int, string> ...$fields) : static

This does not replace previous select(), only adds.

Parameters
$fields : string|array<string|int, string>

alias => column

Tags
throws
InvalidArgumentException
Return values
static

andWhere()

public andWhere(array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'AND' ]) : static
Parameters
$conditions : array<string|int, mixed>|PdbConditionInterface
$combine : string = 'AND'

AND | OR

Return values
static

as()

public as(string|null $class) : static
Parameters
$class : string|null
Tags
throws
InvalidArgumentException
Return values
static

batch()

public batch(int $size) : Generator<string|int, array<string|int, mixed>>
Parameters
$size : int
Tags
throws
InvalidArgumentException
QueryException
ConnectionException
Return values
Generator<string|int, array<string|int, mixed>>

build()

public build([bool $validate = true ]) : array<string|int, mixed>
Parameters
$validate : bool = true
Tags
throws
InvalidConditionException
InvalidArgumentException
Return values
array<string|int, mixed> —

[ sql, params ]

cache()

public cache([string|null $key = null ][, int|bool $ttl = true ]) : static
Parameters
$key : string|null = null
$ttl : int|bool = true

seconds

Return values
static

clone()

Get a copy of this query.

public clone() : static
Return values
static

column()

public column([string|null $field = null ]) : array<string|int, mixed>
Parameters
$field : string|null = null
Tags
throws
InvalidArgumentException
QueryException
ConnectionException
Return values
array<string|int, mixed>

from()

Set the FROM table and alias (optional).

public from(string|array<string|int, string>|PdbQueryInterface $table[, string $alias = null ]) : static
Parameters
$table : string|array<string|int, string>|PdbQueryInterface
$alias : string = null
Tags
throws
InvalidArgumentException
Return values
static

getAlias()

Get the query table alias.

public getAlias() : string
Tags
throws
InvalidArgumentException
Return values
string

group()

public group(string|array<string|int, string> ...$fields) : static

use groupBy

Parameters
$fields : string|array<string|int, string>
Return values
static

groupBy()

public groupBy(string|array<string|int, string> ...$fields) : static
Parameters
$fields : string|array<string|int, string>
Return values
static

indexBy()

Specify a key for array results.

public indexBy(string|null $field) : static

This applies to:

  • all()
  • column()
  • iterator()
Parameters
$field : string|null
Return values
static

innerJoin()

public innerJoin(string|array<string|int, string> $table, string|array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'AND' ]) : static
Parameters
$table : string|array<string|int, string>
$conditions : string|array<string|int, mixed>|PdbConditionInterface
$combine : string = 'AND'
Return values
static

join()

public join(string|array<string|int, string> $table, string|array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'AND' ]) : static
Parameters
$table : string|array<string|int, string>
$conditions : string|array<string|int, mixed>|PdbConditionInterface
$combine : string = 'AND'
Return values
static

jsonSerialize()

public jsonSerialize() : array<string|int, mixed>
Tags
inheritdoc
Return values
array<string|int, mixed>

keyed()

This ends a query.

public keyed(string $key) : array<string|int, mixed>
Parameters
$key : string
Tags
throws
InvalidArgumentException
QueryException
ConnectionException
Return values
array<string|int, mixed> —

[ $key => item ]

leftJoin()

public leftJoin(string|array<string|int, string> $table, string|array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'AND' ]) : static
Parameters
$table : string|array<string|int, string>
$conditions : string|array<string|int, mixed>|PdbConditionInterface
$combine : string = 'AND'
Return values
static

limit()

public limit(int $limit) : static
Parameters
$limit : int
Return values
static

map()

public map([array<string|int, mixed>|string|null $key = null ][, string|null $value = null ]) : array<string|int, mixed>
Parameters
$key : array<string|int, mixed>|string|null = null
$value : string|null = null
Tags
throws
InvalidArgumentException
QueryException
ConnectionException
Return values
array<string|int, mixed>

offset()

public offset(int $offset) : static
Parameters
$offset : int
Return values
static

one()

public one([bool|null $throw = null ]) : array<string|int, mixed>|object|null
Parameters
$throw : bool|null = null
Tags
throws
InvalidArgumentException
QueryException
ConnectionException
Return values
array<string|int, mixed>|object|null

order()

public order(string|array<string|int, string> ...$fields) : static

use orderBy

Parameters
$fields : string|array<string|int, string>
Return values
static

orderBy()

public orderBy(string|array<string|int, string> ...$fields) : static
Parameters
$fields : string|array<string|int, string>
Return values
static

orWhere()

public orWhere(array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'OR' ]) : static
Parameters
$conditions : array<string|int, mixed>|PdbConditionInterface
$combine : string = 'OR'

AND | OR

Return values
static

select()

Select a list of fields.

public select(string|array<string|int, string> ...$fields) : static

Note, this will replace any previous select().

Parameters
$fields : string|array<string|int, string>

alias => column

Tags
throws
InvalidArgumentException
Return values
static

throw()

Emit RowMissingExceptions if the record is not found.

public throw([bool $throw = true ]) : static

This applies to:

  • one()
  • value()
Parameters
$throw : bool = true
Return values
static

toArray()

Convert this object to an array.

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

update()

Update the object with a new configuration.

public update(iterable<string|int, mixed> $config) : void
Parameters
$config : iterable<string|int, mixed>

value()

public value([string|null $field = null ][, bool|null $throw = null ]) : string|null
Parameters
$field : string|null = null
$throw : bool|null = null
Tags
throws
InvalidArgumentException
QueryException
ConnectionException
Return values
string|null

_afterBuild()

protected _afterBuild(string &$sql, array<string|int, mixed> &$params) : void
Parameters
$sql : string
$params : array<string|int, mixed>

_build()

protected _build([bool $validate = true ]) : array<string|int, mixed>
Parameters
$validate : bool = true
Tags
throws
InvalidConditionException
InvalidArgumentException
Return values
array<string|int, mixed> —

[ sql, params ]

_join()

protected _join(string $type, string|array<string|int, string> $table, string|array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'AND' ]) : static
Parameters
$type : string
$table : string|array<string|int, string>
$conditions : string|array<string|int, mixed>|PdbConditionInterface
$combine : string = 'AND'
Tags
throws
InvalidArgumentException
Return values
static
On this page

Search results