# Engine

<mark style="color:red;">**Engine**</mark> is initialized with Snowflake connection and <mark style="color:purple;">**config**</mark>. It is used to build, format and execute DDL commands by <mark style="color:green;">**resolvers**</mark>.

Engine is represented by class `SnowDDLEngine`, which is located in [`engine.py`](https://github.com/littleK0i/SnowDDL/blob/master/snowddl/engine.py).

One <mark style="color:red;">**engine**</mark> is expected to be reused by multiple <mark style="color:green;">**resolvers**</mark> executed in the correct order.

### Engine settings

Settings are represented by class `SnowDDLSettings`.

You may find the most recent version of settings in [`settings.py`](https://github.com/littleK0i/SnowDDL/blob/master/snowddl/settings.py).

Settings starting with `execute_` control the execution behaviour. If value is `True`, DDL commands of this type will be executed. If value is `False`, commands will be "suggested" (dumped for manual execution) instead.

### Engine context

Engine collects information about Snowflake connection context during initialization.

You should check which context properties are available in [`context.py`](https://github.com/littleK0i/SnowDDL/blob/master/snowddl/context.py).

### Methods

* `__init__(connection: SnowflakeConnection, config: SnowDDLConfig, settings: SnowDDLSettings)`\
  Initialize <mark style="color:red;">**engine**</mark> with Snowflake connection, <mark style="color:purple;">**config**</mark> and settings.<br>
* `format(sql, params=None)`\
  Formats SQL query using SnowDDL [formatter](/advanced/query-builder-and-formatter.md).<br>
* `query_builder()`\
  Create sand returns new [query builder](/advanced/query-builder-and-formatter.md).<br>
* `describe_meta(sql, params=None)`\
  Describes SQL query, compiles it without actually executing and returns information about result columns. If SQL query cannot be compiled, throws an exception.<br>
* `execute_meta(sql, params=None)`\
  Executes SQL query returning metadata information, usually `SHOW` commands.<br>
* `execute_context_ddl(sql, params=None)`\
  Executes DDL command which is used to initialize the current context. It is normally used to create technical role for [env prefix](/guides/other-guides/env-prefix.md) feature.<br>
* `execute_safe_ddl(sql, params=None, condition=True)`\
  Executes DDL command which is classified as ["safe"](/guides/other-guides/safe-unsafe.md), usually `CREATE`. Optionally checks the expression in `condition` argument and executes command only if expression is `True`. Otherwise, it only "suggests" DDL command.<br>
* `execute_unsafe_ddl(sql, params=None, condition=True)`\
  Executes DDL command which is classified as ["unsafe"](/guides/other-guides/safe-unsafe.md), usually `ALTER`, `DROP`. Optionally checks the expression in `condition` argument and executes command only if expression is `True`. Otherwise, it only "suggests" DDL command.

### Properties

* **.connection** (SnowflakeConnection);
* **.config** (SnowDDLConfig);
* **.settings** (SnowDDLSettings);
* **.logger** (Logger) - pre-initialized logger with name `snowddl.engine`;
* **.executor** (ThreadPoolExecutor) - pre-initialized pool executor;
* **.executed\_ddl** (list) - list of raw DDL commands which were executed by engine;
  * *{items}* (str) - SQL query;
* **.suggested\_ddl** (list) - list of raw DDL commands which were suggested for manual execution;
  * *{items}* (str) - SQL query;
* **.context** (SnowDDLContext) - pre-initialized context information (version, edition, current warehouse, etc.) extracted from Snowflake account;
* **.schema\_cache** (SnowDDLSchemaCache) - pre-initialized cache with databases and schemas, used to reduce the number of metadata queries performed by <mark style="color:green;">**resolvers**</mark>;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.snowddl.com/advanced/architecture-overview/engine.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
