Download the PHP package hectororm/query without Composer
On this page you can find all versions of the php package hectororm/query. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hectororm/query
More information about hectororm/query
Files in hectororm/query
Package query
Short Description Hector Query
License MIT
Homepage https://gethectororm.com
Informations about the package query
Hector Query
Hector Query is the query module of Hector ORM. Can be used independently of ORM.
Installation
Composer
You can install Hector Query with Composer, it's the recommended installation.
Dependencies
- PHP ^8.0
- Packages dependencies:
- hectororm/connection
Usage
QueryBuilder
You can initialize the query builder with a Connection
object.
Select / Insert / Update / Delete / Union
You can do a select/insert/update/delete request with specific objects:
- Select :
Hector\Query\Select
class - Insert :
Hector\Query\Insert
class - Update :
Hector\Query\Update
class - Delete :
Hector\Query\Delete
class - Union :
Hector\Query\Union
class
All this classes implements StatementInterface
interface. This interface provides one method to get statement and bindings:
StatementInterface::getStatement(BindParamList $bindParams)
Example of use:
Conditions
Hector Query
has support of having and where conditions. Methods are sames, just replace "where" by "having" in method
name.
Where / Having
Shortcuts
QueryBuilder::whereIn($column, array $values)
QueryBuilder::whereNotIn($column, array $values)
QueryBuilder::whereBetween($column, $value1, $value2)
QueryBuilder::whereNotBetween($column, $value1, $value2)
QueryBuilder::whereGreaterThan($column, $value)
QueryBuilder::whereGreaterThanOrEqual($column, $value)
QueryBuilder::whereLessThan($column, $value)
QueryBuilder::whereLessThanOrEqual($column, $value)
QueryBuilder::whereExists($statement)
QueryBuilder::whereNotExists($statement)
QueryBuilder::whereContains($string)
QueryBuilder::whereStartsWith($string)
QueryBuilder::whereEndsWith($string)
Columns
You can specify columns name and alias with method:
QueryBuilder::column($column, $alias)
Repeat call of this method, add a new column to the result rows ; you can reset columns with method QueryBuilder::resetColumns()
.
Or pass an array of column names:
QueryBuilder::columns(array $columnNames)
Group
You can group results with method:
QueryBuilder::groupBy($column)
Repeat call of this method, add a new group ; you can reset groups with method QueryBuilder::resetGroups()
.
If you want set WITH ROLLUP
modifier to your statement, you can do it with method:
QueryBuilder::groupByWithRollup(bool $withRollup = true)
Order
You can order results with method:
QueryBuilder::orderBy($column, $order)
Repeat call of this method, add a new order ; you can reset orders with method QueryBuilder::resetOrder()
.
A shortcut is available if you want to do a random order:
QueryBuilder::random()
Limit
You can limit results with methods:
QueryBuilder::limit(int $limit, int $offset = null)
QueryBuilder::offset(int $offset)
If you want reset limits, uses method QueryBuilder::resetLimit()
.
Assignments
For Insert/Update statements, you need to assign values with method :
QueryBuilder::assign($column, $value)
Repeat call of this method, add a new assignment to the statement ; you can reset assignments with method QueryBuilder::resetAssignments()
.
Or pass an associative array with column names and values:
QueryBuilder::assigns(array|StatementInterface $columnValues)
Jointures
Three methods are available to do jointures:
QueryBuilder::innerJoin($table, $condition, ?string $alias = null)
QueryBuilder::leftJoin($table, $condition, ?string $alias = null)
QueryBuilder::rightJoin($table, $condition, ?string $alias = null)
If you want reset jointures, uses method QueryBuilder::resetJoin()
.
Union
An Union
class is available to make unions with select.
Union
class is a StatementInterface
, so refers to the related paragraph to use it.
Fetch results
3 methods to fetch result:
QueryBuilder::fetchOne(): ?array
Get first row of statement results.QueryBuilder::fetchAll(): Generator
Get all rows of statement results, usesGenerator
class.QueryBuilder::fetchColumn(int $column = 0): Generator
Get specified column value of all rows of statement results, usesGenerator
class.
To known how use Generator, refers to the PHP documentation: https://www.php.net/manual/class.generator.php
Count results
A shortcut method is available in QueryBuilder
class to count results.
This method reset columns, limit and order of query ; but don't modify the query builder, so you can continue to use it to get results for example.
Exists
A shortcut method is available in QueryBuilder
class to do an exists query.
This method don't modify the query builder, so you can continue to use it to get results for example.
Insert / Update / Delete
Shortcut methods are available in QueryBuilder
class to do an insert, an update or a delete.
These methods don't modify the query builder, so you can continue to use it to get results for example.