> For the complete documentation index, see [llms.txt](https://docs.snowddl.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.snowddl.com/advanced/architecture-overview/engine.md).

# 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>;
