---
title: "Query Config"
description: "Declarative Query Configuration"
type: "docs"
category: "doc"
tags: []
authors: [Anonymous]
date: "2026-09-09"
last_update: "2026-09-09"
time_minutes: 1
draft: false
unlisted: false
url: "https://www.derafu.dev/docs/data/query/query-config"
---

# 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](./query-builder) page, under the **Declarative Query Configuration** section.

## Quick Reference

```php
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 |

For full documentation, examples, and API-driven query patterns, see [Query Builder → Declarative Query Configuration](./query-builder#declarative-query-configuration).



---
Last updated on 09/09/2026

