Skip to content

Configuration

Miguel Muscat edited this page May 21, 2022 · 1 revision

The Atlas configuration is used to determine how queries are compiled. It is created with an associative array that maps a query type identifier string to a QueryTypeInterface instance, which are responsible for rendering queries into strings.

use RebelCode\Atlas\Config;
use RebelCode\Atlas\QueryType;

$config = new Config([
    QueryType::SELECT => new QueryType\Select(),
    QueryType::INSERT => new QueryType\Insert(),
    QueryType::UPDATE => new QueryType\Update(),
    // ...
]);

When creating a config, you MUST specify all of the core query types. For this reason, it is recommended to start with the default config and then add overrides:

$config = Config::createDefault()->withOverrides([
    QueryType::SELECT => new CustomSelect();
]);

Custom query types

Custom query types may also be added. But queries with custom types need to be created manually:

$config = Config::createDefault()->withOverrides([
    'custom' => new CustomType();
]);

$query = new Query($config->getQueryType('custom'), [
    // Query data ...
]);

Tables provide a query() method to simplify this process. They will include their name in the query data using 'table' key:

$table = $atlas->table('users');
$query = $table->query('custom', [
    'columns' => ['id', 'name']
]);

$query->get('table');    // 'users'
$query->get('columns');  // ['id', 'name']

Refer to the Compiling queries guide to see how to implement query rendering.

Clone this wiki locally