Table
Table
Fluent table query facade for building and executing adapter-backed SQL operations.
class TableThis class wraps a query builder and provides convenience methods for selecting, inserting, updating, deleting, and metadata operations scoped to a single database table.
Properties
adapter
Database adapter used to prepare and execute SQL statements.
private Adapter $adapterType: Hazaar\DBI\Adapter
queryBuilder
Query builder instance used to compose SQL for this table context.
private QueryBuilder $queryBuilderType: Hazaar\DBI\Interface\QueryBuilder
name
Physical table name in the connected database.
private string $nameType: string
alias
public string $aliasType: string
Methods
__construct
Create a table query context bound to a specific adapter and table.
public __construct(Adapter $adapter, array|string $name, ?string $alias): voidParameters
| Parameter | Type | Description |
|---|---|---|
$adapter | Hazaar\DBI\Adapter | active database adapter |
$name | array | string |
$alias | string | optional table alias for generated SQL |
__toString
Cast the current query builder state to SQL.
public __toString(): stringReturns: string
toString
Get the SQL string for the current query state.
public toString(): stringReturns: string
getName
Get the configured table name.
public getName(): stringReturns: string
exists
Determine whether the table or matching records exist.
public exists(null|array|string $criteria): boolReturns: bool
When $criteria is null, this checks table existence in the schema. Otherwise it executes an EXISTS query against this table.
Parameters
| Parameter | Type | Description |
|---|---|---|
$criteria | null | array |
select
Define the columns to select.
public select(mixed $columns = '*'): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$columns | mixed | *, column name, or builder-supported column map/list |
distinct
Mark the SELECT as DISTINCT for one or more columns.
public distinct(string $columns): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$columns | string |
from
Override the FROM clause for the current query.
public from(array|string $table, ?string $alias): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | array | string |
$alias | string | optional source alias |
limit
Set a LIMIT clause for the query.
public limit(int $limit): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$limit | int | maximum number of rows to return |
offset
Set an OFFSET clause for the query.
public offset(int $offset): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | int | number of rows to skip before returning data |
order
Add ORDER BY columns to the current query.
public order(array|string $columns, int $direction = 'SORT_ASC'): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$columns | array | string |
$direction | int | sort direction (SORT_ASC or SORT_DESC) for string input |
group
Add GROUP BY columns to the query.
public group(string $columns): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$columns | string |
having
Add a HAVING clause to the grouped query.
public having(array $having): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$having | array |
join
Join another table to the current query.
public join(array|string $table, array|string $on, ?string $alias, string $type = 'INNER'): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | array | string |
$on | array | string |
$alias | string | optional alias for the joined table |
$type | string | join type (INNER, LEFT, RIGHT, OUTER, FULL, CROSS) |
leftJoin
Add a LEFT JOIN to the current query.
public leftJoin(array|string $table, array|string $on, ?string $alias): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | array | string |
$on | array | string |
$alias | string | optional alias for the joined table |
rightJoin
Add a RIGHT JOIN to the current query.
public rightJoin(array|string $table, array|string $on, ?string $alias): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | array | string |
$on | array | string |
$alias | string | optional alias for the joined table |
innerJoin
Add an INNER JOIN to the current query.
public innerJoin(array|string $table, array|string $on, ?string $alias): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | array | string |
$on | array | string |
$alias | string | optional alias for the joined table |
outerJoin
Add an OUTER JOIN to the current query.
public outerJoin(array|string $table, array|string $on, ?string $alias): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | array | string |
$on | array | string |
$alias | string | optional alias for the joined table |
fullJoin
Add a FULL JOIN to the current query.
public fullJoin(array|string $table, array|string $on, ?string $alias): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | array | string |
$on | array | string |
$alias | string | optional alias for the joined table |
crossJoin
Add a CROSS JOIN to the current query.
public crossJoin(array|string $table, array|string $on, ?string $alias): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | array | string |
$on | array | string |
$alias | string | optional alias for the joined table |
union
Combine this SELECT with another query using UNION.
public union(Table $table): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | Hazaar\DBI\Table | table containing the query to union with |
unionAll
Combine this SELECT with another query using UNION ALL.
public unionAll(Table $table): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | Hazaar\DBI\Table | table containing the query to union with |
intersect
Intersect this SELECT with another query using INTERSECT.
public intersect(Table $table): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | Hazaar\DBI\Table | table containing the query to intersect with |
except
Exclude rows from this SELECT that appear in another query using EXCEPT.
public except(Table $table): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$table | Hazaar\DBI\Table | table containing the query to exclude |
prepareSelect
Prepare a reusable SELECT statement with named criteria placeholders.
public prepareSelect(array $columns, array $criteriaNames): StatementReturns: Hazaar\DBI\Statement
Parameters
| Parameter | Type | Description |
|---|---|---|
$columns | array | columns to include in the projection |
$criteriaNames | array | columns exposed as WHERE placeholders |
insert
Insert one or more rows, or a model instance, into the table.
public insert(array|Insertable $values, array|string|null $returning, array|string|null $conflictTarget, array|bool|null $conflictUpdate, ?Table $table): mixedReturns: mixed
Supports optional RETURNING and conflict handling (upsert-like behavior) based on adapter capabilities. When an Insertable (such as a model) is passed, its values are extracted via toArray('dbiWrite') and, if $returning is not explicitly given, it defaults to whichever of the model's dbiInsert/dbiWrite keys were not already supplied so the model can be hydrated from the database defaults. If the value is also a Struct, it is hydrated with the returned columns and returned in place of the raw result.
Parameters
| Parameter | Type | Description |
|---|---|---|
$values | array | Hazaar\DBI\Interface\Insertable |
$returning | array | string |
$conflictTarget | array | string |
$conflictUpdate | array | bool |
$table | Hazaar\DBI\Table | reserved parameter for API compatibility |
prepareInsert
Prepare a reusable INSERT statement from a list of columns.
public prepareInsert(array $columnNames): StatementReturns: Hazaar\DBI\Statement
Parameters
| Parameter | Type | Description |
|---|---|---|
$columnNames | array | column names that will be accepted as values |
update
Update rows matching the provided criteria, or a model instance's own key fields.
public update(array|Insertable $values, array|string $where, null|array|string $returning): mixedReturns: mixed
Supports optional RETURNING handling. When an Insertable (such as a model) is passed, its values are extracted via toArray('dbiWrite'). If the value is also a Struct, $where is instead treated as the name(s) of the model's own properties used to build the update criteria (e.g. primary key columns); $returning, if not explicitly given, defaults to whichever of the model's dbiWrite keys were not already supplied so the model can be refreshed from the database; and the model is updated with the returned columns and returned in place of the raw result.
Parameters
| Parameter | Type | Description |
|---|---|---|
$values | array | Hazaar\DBI\Interface\Insertable |
$where | array | string |
$returning | null | array |
prepareUpdate
Prepare a reusable UPDATE statement with named update and criteria fields.
public prepareUpdate(array $columnNames, array $criteriaNames): StatementReturns: Hazaar\DBI\Statement
Parameters
| Parameter | Type | Description |
|---|---|---|
$columnNames | array | columns that will be updated |
$criteriaNames | array | columns used in the WHERE clause |
delete
Delete rows matching the provided criteria.
public delete(array|string $where, null|array|string $returning): array|false|intReturns: array|false|int
When $returning is given, a RETURNING clause is emitted and the deleted rows are returned instead of the affected-row count, letting a lookup-and-delete be done as one atomic statement (e.g. single-use token redemption). Pass '*' for every column, or a column name/list. Supported on PostgreSQL and SQLite (>= 3.35).
Parameters
| Parameter | Type | Description |
|---|---|---|
$where | array | string |
$returning | null | array |
prepareDelete
Prepare a reusable DELETE statement with named criteria placeholders.
public prepareDelete(array $criteriaNames): StatementReturns: Hazaar\DBI\Statement
Parameters
| Parameter | Type | Description |
|---|---|---|
$criteriaNames | array | columns used as WHERE placeholders |
deleteAll
Delete all rows from the table.
public deleteAll(): false|intReturns: false|int
truncate
Truncate all rows from the table.
public truncate(bool $cascade): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$cascade | bool | whether related dependent data should also be removed |
find
Execute a SELECT query with optional criteria and selected columns.
public find(null|array|string $where, mixed $columns, bool $clobberDupNamedCols): false|ResultReturns: false|Hazaar\DBI\Interface\Result
Parameters
| Parameter | Type | Description |
|---|---|---|
$where | null | array |
$columns | mixed | |
$clobberDupNamedCols | bool | suppress the automatic FETCH_NAMED upgrade this Result would otherwise apply on fetch()/fetchAll() when this query has select groups, forcing plain FETCH_ASSOC instead |
where
Add a WHERE clause to the current query.
public where(array|string $where): selfReturns: self
Parameters
| Parameter | Type | Description |
|---|---|---|
$where | array | string |
findOne
Fetch the first matching row as an associative array.
public findOne(null|array|string $where, mixed $columns, bool $clobberDupNamedCols): array|falseReturns: array|false
Parameters
| Parameter | Type | Description |
|---|---|---|
$where | null | array |
$columns | mixed | |
$clobberDupNamedCols | bool | suppress the automatic FETCH_NAMED upgrade this fetch would otherwise get when this query has select groups, forcing plain FETCH_ASSOC instead |
findOneModel
Fetch the first matching row and hydrate it into a model instance.
public findOneModel(string $model, array|string $where): false|StructReturns: false|Hazaar\Model\Struct
Parameters
| Parameter | Type | Description |
|---|---|---|
$model | string | fully qualified model class name |
$where | array | string |
findOneRow
Fetch the first matching row as a Row object.
public findOneRow(array|string $where, array|string|null $columns): false|RowReturns: false|Hazaar\DBI\Row
Parameters
| Parameter | Type | Description |
|---|---|---|
$where | array | string |
$columns | array | string |
fetchAll
Fetch all rows for the current query.
public fetchAll(?string $keyColumn, bool $clobberDupNamedCols): array|falseReturns: array|false
Parameters
| Parameter | Type | Description |
|---|---|---|
$keyColumn | string | optional column used as the key in the returned array |
$clobberDupNamedCols | bool | suppress the automatic FETCH_NAMED upgrade this fetch would otherwise get when this query has select groups, forcing plain FETCH_ASSOC instead |
fetchAllColumn
Fetch every value from a single selected column.
public fetchAllColumn(string $columnName, mixed $fetchArgument, bool $clobberDupNamedCols): array|falseReturns: array|false
Parameters
| Parameter | Type | Description |
|---|---|---|
$columnName | string | column to extract |
$fetchArgument | mixed | reserved parameter for API compatibility |
$clobberDupNamedCols | bool | suppress the automatic FETCH_NAMED upgrade this fetch would otherwise get when this query has select groups, forcing plain FETCH_ASSOC instead |
toArray
Materialize the current query result as an array of row arrays.
public toArray(): arrayReturns: array
count
Count rows matching the current query criteria.
public count(): intReturns: int
describe
Describe table columns using adapter-specific metadata.
public describe(): array|falseReturns: array|false
errorInfo
Get the adapter's most recent error information.
public errorInfo(): arrayReturns: array
execute
Execute the current SQL and return the first column from the first row.
public execute(): false|intReturns: false|int
create
Create the table in the database using the provided column definition.
public create(array $columns): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$columns | array | adapter-specific table column/schema definition |
drop
Drop the table from the database.
public drop(): boolReturns: bool
getPrimaryKey
Get the primary key constraint metadata for this table.
public getPrimaryKey(): array|falseReturns: array|false
reset
Reset the query builder state for this table context.
public reset(): selfReturns: self
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000