Declarative Query Configuration

The QueryConfig class provides a configuration-based alternative to the fluent builder API. It is covered in detail in the Query Builder page, under the Declarative Query Configuration section.

Quick Reference

use Derafu\Query\Config\QueryConfig;

// From an array.
$config = new QueryConfig([
    'table'   => 'products',
    'select'  => 'id, name, price',
    'where'   => 'category?=electronics',
    'orderBy' => ['price' => 'DESC'],
    'limit'   => 10,
]);
$result = $config->applyTo($queryBuilder)->execute();

// From a YAML file.
$config = QueryConfig::fromYamlFile('queries/product_report.yaml');

// From a JSON file.
$config = QueryConfig::fromJsonFile('queries/sales.json');

// Auto-detect format by extension.
$config = QueryConfig::fromFile('queries/report.yaml');

Supported Configuration Keys

Key Description
table Table name (FROM clause)
alias Table alias
select Columns to select
distinct true to add DISTINCT
where WHERE condition(s)
andWhere Additional AND condition(s)
orWhere OR condition(s)
andWhereOr AND with nested OR groups
innerJoin {table, condition, alias?}
leftJoin {table, condition, alias?}
rightJoin {table, condition, alias?}
crossJoin {table, alias?}
groupBy GROUP BY column(s)
having HAVING condition(s)
orderBy {column: direction} pairs
limit Max rows to return
offset Rows to skip

Known options are type-checked by the QueryConfig constructor before a builder is modified. Absent/null options are skipped; malformed non-null values are rejected. Unknown options are retained but not applied. JSON/YAML loaders reject numeric root keys. See the detailed configuration validation rules, including nested conditions, JOIN shapes and distinct: false behavior.

JOIN definitions must be maps with string field names. Positional lists and numeric field names are rejected; additional named fields are preserved without affecting the query. Arrays with numeric keys remain valid inside those additional field values.

For full documentation, examples, and API-driven query patterns, see Query Builder → Declarative Query Configuration.

On this page

Last updated on 30/10/2026 by Anonymous