Documentation

QueryBuilder
in package

Table of Contents

Constants

DEFAULT_SELECT  = '*'

Properties

$collections  : array<string|int, mixed>
$driver  : null|DriverBase
$fields  : array<string|int, mixed>
$filters  : array<string|int, mixed>
$formatting  : array<string|int, mixed>
$groups  : array<string|int, mixed>
$joins  : array<string|int, mixed>
$limit  : null|int
$logger  : LoggerInterface
$offset  : null|int
$sorts  : array<string|int, mixed>

Methods

__construct()  : mixed
add()  : int
Alias for insert method.
addMultiple()  : int
Alias for insert multiple method.
create()  : QueryBuilder
delete()  : int
Execute a query to delete record(s) and returns the number of affected rows.
destroy()  : int
Alias for delete method.
fetch()  : null|array<string|int, mixed>
Simple query mechanism to find record(s) by a field and its value.
filter()  : QueryBuilder
Add a filter to be used in the query to be executed.
filterList()  : QueryBuilder
Add a list of filters to be used in the query to be executed.
filterOn()  : QueryBuilder
Create a filter to be used in the query to be executed.
filterOnFields()  : QueryBuilder
Create a filter to be used in the query to be executed.
formatAs()  : QueryBuilder
Format the query result.
get()  : null|array<string|int, mixed>
Alias for select method.
groupOn()  : QueryBuilder
Group the query result.
insert()  : int
Execute a query inserting a record and returns the corresponding primary id.
insertMultiple()  : int
Execute a query inserting multiple records in a single statement.
joinOn()  : QueryBuilder
Join collections to the query.
limit()  : QueryBuilder
Limit the query result.
modify()  : int
Alias for update method.
offset()  : QueryBuilder
Offset the query result.
orderOn()  : QueryBuilder
Order the query result.
select()  : null|array<string|int, mixed>
Execute a query finding record(s) and returns the result.
sortOn()  : QueryBuilder
Alias for order method.
update()  : int
Execute a query updating record(s) and return the number of affected rows.

Constants

Properties

$collections

private array<string|int, mixed> $collections = []

$formatting

private array<string|int, mixed> $formatting = []

Methods

__construct()

public __construct(null|DriverBase $driver, array<string|int, mixed> $collections[, LoggerInterface $logger = new NullLogger() ]) : mixed
Parameters
$driver : null|DriverBase
$collections : array<string|int, mixed>
$logger : LoggerInterface = new NullLogger()

add()

Alias for insert method.

public add(array<string|int, mixed> $fieldsWithValues) : int
Parameters
$fieldsWithValues : array<string|int, mixed>
Return values
int

addMultiple()

Alias for insert multiple method.

public addMultiple(array<string|int, mixed> $fieldsWithValues) : int
Parameters
$fieldsWithValues : array<string|int, mixed>
Return values
int

create()

public static create([null|DriverBase $driver = null ][, array<string|int, mixed> $collections = [] ][, LoggerInterface $logger = new NullLogger() ]) : QueryBuilder
Parameters
$driver : null|DriverBase = null
$collections : array<string|int, mixed> = []
$logger : LoggerInterface = new NullLogger()
Return values
QueryBuilder

delete()

Execute a query to delete record(s) and returns the number of affected rows.

public delete() : int
  • Example use: $database->query('CollectionName')->filterOn( ... )->delete()
Return values
int

destroy()

Alias for delete method.

public destroy() : int
Return values
int

fetch()

Simple query mechanism to find record(s) by a field and its value.

public fetch(string $field, mixed $value[, Operator $operator = Operator::EQ ]) : null|array<string|int, mixed>
  • Example use: $database->query('CollectionName')->fetch('Name', 'John')
  • Example use: $database->query('CollectionName')->fetch('Age', [25, 55], Operator::IN)
Parameters
$field : string
$value : mixed
$operator : Operator = Operator::EQ
Return values
null|array<string|int, mixed>

filter()

Add a filter to be used in the query to be executed.

public filter(array<string|int, mixed> $filter[, LogicalOperator $logicalOperator = LogicalOperator::AND ]) : QueryBuilder
Parameters
$filter : array<string|int, mixed>

['Name', Operator::EQ, 'John', LogicalOperator::AND]

  • Example use: $database->query('CollectionName')->filter(['Name', Operator::EQ, 'John', LogicalOperator::AND])
$logicalOperator : LogicalOperator = LogicalOperator::AND
Return values
QueryBuilder

filterList()

Add a list of filters to be used in the query to be executed.

public filterList(array<string|int, mixed> $filters[, LogicalOperator $logicalOperator = LogicalOperator::AND ]) : QueryBuilder
Parameters
$filters : array<string|int, mixed>

[['Name', Operator::EQ, 'John', LogicalOperator::AND], [ ... ], [ ... ]]

  • Example use: $database->query('CollectionName')->filterList([['Name', Operator::EQ, 'John', LogicalOperator::AND]])
$logicalOperator : LogicalOperator = LogicalOperator::AND
Return values
QueryBuilder

filterOn()

Create a filter to be used in the query to be executed.

public filterOn(string $field, mixed $value[, Operator $operator = Operator::EQ ][, LogicalOperator $logicalOperator = LogicalOperator::AND ]) : QueryBuilder
Parameters
$field : string

'Name'

$value : mixed

'John'

  • Example use: $database->query('CollectionName')->filterOn('Name', 'John')
$operator : Operator = Operator::EQ
$logicalOperator : LogicalOperator = LogicalOperator::AND
Return values
QueryBuilder

filterOnFields()

Create a filter to be used in the query to be executed.

public filterOnFields(array<string|int, mixed> $fieldsWithValues[, Operator $operator = Operator::EQ ][, LogicalOperator $logicalOperator = LogicalOperator::AND ]) : QueryBuilder
Parameters
$fieldsWithValues : array<string|int, mixed>

['Name' => 'John', 'Lastname' => 'Doe', 'UserID' => 25, ..., ...]

  • Example use: $database->query('CollectionName')->filterList(['Name' => 'John', 'Deleted' => 0 ])
$operator : Operator = Operator::EQ
$logicalOperator : LogicalOperator = LogicalOperator::AND
Return values
QueryBuilder

formatAs()

Format the query result.

public formatAs(Format $format[, mixed $args = null ]) : QueryBuilder
  • Example use: $database->query('CollectionName')->formatAs(Format::STD_CLASS)
  • Example use: $database->query('CollectionName')->formatAs(Format::CUSTOM_OBJECT, ClassName::class)
Parameters
$format : Format
$args : mixed = null
Return values
QueryBuilder

get()

Alias for select method.

public get(string ...$fields) : null|array<string|int, mixed>
Parameters
$fields : string
Return values
null|array<string|int, mixed>

groupOn()

Group the query result.

public groupOn(string ...$fields) : QueryBuilder
  • Example use: $database->query('CollectionName')->groupOn('Name')
  • Example use: $database->query('CollectionName')->groupOn('Name', 'Age')
  • Example use: $database->query('CollectionName')->groupOn('Name, Age')
Parameters
$fields : string
Return values
QueryBuilder

insert()

Execute a query inserting a record and returns the corresponding primary id.

public insert(array<string|int, mixed> $fieldsWithValues) : int
  • Example use: $database->query('CollectionName')->insert(['Username' => 'John', 'Password' => '1234'])
Parameters
$fieldsWithValues : array<string|int, mixed>
Return values
int

insertMultiple()

Execute a query inserting multiple records in a single statement.

public insertMultiple(array<string|int, mixed> $fieldsWithValues) : int

Returns the primary id of the first inserted record.

  • Example use: $database->query('CollectionName')->insert([['Username' => 'John', 'Password' => '1234']])
Parameters
$fieldsWithValues : array<string|int, mixed>
Return values
int

joinOn()

Join collections to the query.

public joinOn(string $currentCollectionWithField, Join $join[, string|null $onCollectionWithField = null ]) : QueryBuilder
  • Example use: $database->query('CollectionName')->join('Collection1.Field', Join::INNER, 'Collection2.Field')
  • Example use: $database->query('CollectionName')->join('Collection1.Field = Collection2.Field', Join::LEFT)
Parameters
$currentCollectionWithField : string
$join : Join
$onCollectionWithField : string|null = null
Return values
QueryBuilder

limit()

Limit the query result.

public limit(int $limit) : QueryBuilder
  • Example use: $database->query('CollectionName')->limit(10)
  • Example use: $database->query('CollectionName')->limit('10')
Parameters
$limit : int
Return values
QueryBuilder

modify()

Alias for update method.

public modify(array<string|int, mixed> $fieldsWithValues) : int
Parameters
$fieldsWithValues : array<string|int, mixed>
Return values
int

offset()

Offset the query result.

public offset(int $offset) : QueryBuilder
  • Example use: $database->query('CollectionName')->offset(10)
Parameters
$offset : int
Return values
QueryBuilder

orderOn()

Order the query result.

public orderOn(array<string|int, mixed> $sortFields) : QueryBuilder
  • Example use: $database->query('CollectionName')->sortOn(['Name' => Sorts::DESC])
  • Example use: $database->query('CollectionName')->sortOn(['Name' => Sorts::ASC, 'Age' => Sorts::DESC])
Parameters
$sortFields : array<string|int, mixed>
Return values
QueryBuilder

select()

Execute a query finding record(s) and returns the result.

public select(string ...$fields) : null|array<string|int, mixed>
  • Example use: $database->query('CollectionName')->select('*')
  • Example use: $database->query('CollectionName')->select('Name', 'Age')
  • Example use: $database->query('CollectionName')->select('Name, Age')
  • Example use: $database->query('CollectionName')->select('Name as Username')
  • Example use: $database->query('CollectionName')->select([ 'Name', 'Age', 'Username' ])
Parameters
$fields : string
Return values
null|array<string|int, mixed>

sortOn()

Alias for order method.

public sortOn(array<string|int, mixed> $sortFields) : QueryBuilder
Parameters
$sortFields : array<string|int, mixed>
Return values
QueryBuilder

update()

Execute a query updating record(s) and return the number of affected rows.

public update(array<string|int, mixed> $fieldsWithValues) : int
  • Example use: $database->query('CollectionName')->update(['Active' => 1])
  • Example use: $database->query('CollectionName')->filterOn( ... )->update(['Username' => 'Jane', 'Password' => 'password'])
Parameters
$fieldsWithValues : array<string|int, mixed>
Return values
int

        
On this page

Search results