> For the complete documentation index, see [llms.txt](https://utca.knowledgator.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://utca.knowledgator.com/datasources/db/sql.md).

# SQL

## Module: [implementation](/framework-structure.md#implementation).datasources.db

***

***

## <mark style="color:green;">SQLAction</mark>

SQL action without returns. Expected that this action will execute statements that don't return data from DB.&#x20;

Subclass of [**Action**](/core/action.md)**.** Type of [**Action**](/core/action.md)**\[Dict\[str, Any], None]**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**session**</mark>**&#x20;(**[**SQLSessionFactory**](#sqlsessionfactory)**):** Session to use.
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):**\
  Expected keys:&#x20;
  * <mark style="color:red;">**"statement"**</mark>**&#x20;(Any):** [**SQLAlchemy statement**](https://docs.sqlalchemy.org/en/20/core/expression_api.html)**.**
  * <mark style="color:red;">**"kwargs"**</mark> **(Dict\[str, Any], optional):** Extra arguments.

#### In details about statements, see:

{% embed url="<https://docs.sqlalchemy.org/en/20/core/expression_api.html>" %}

***

***

***

## <mark style="color:green;">SQLActionWithReturns</mark>

SQL action with returns. Subclass of [**Action**](/core/action.md)**.** Type of [**Action**](/core/action.md)**\[Dict\[str, Any], Any]**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**session**</mark>**&#x20;(**[**SQLSessionFactory**](#sqlsessionfactory)**):** Session to use.
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):**\
  Expected keys:&#x20;
  * <mark style="color:red;">**"statement"**</mark>**&#x20;(Any):** [**SQLAlchemy statement**](https://docs.sqlalchemy.org/en/20/core/expression_api.html).
  * <mark style="color:red;">**"kwargs"**</mark>**&#x20;(Dict\[str, Any], optional):** Extra arguments.

#### Returns:

* **List\[Any]:** Result of query.

#### In details about statements, see:

{% embed url="<https://docs.sqlalchemy.org/en/20/core/expression_api.html>" %}

***

***

***

## <mark style="color:green;">SQLSessionFactory</mark>

Sessions manager

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**url**</mark>**&#x20;(str):** connection URL of the DB.
* <mark style="color:orange;">**echo**</mark>**&#x20;(bool, optional):** If equals to True, logs debug info. Defaults to False.

***

### <mark style="color:blue;">create</mark>

Create session

#### Returns:

* Session

***

### <mark style="color:blue;">close\_all</mark>

Close all sessions

***

### <mark style="color:blue;">create\_tables</mark>

Create all tables

#### Arguments:

* <mark style="color:orange;">**tables\_class**</mark>**&#x20;(Type\[**[**DeclarativeBase**](https://docs.sqlalchemy.org/en/20/orm/mapping_api.html#sqlalchemy.orm.DeclarativeBase)**], optional):** Base class of tables that will be used to trigger creation. Defaults to [**BaseModel**](#basemodel).

#### See more:

{% embed url="<https://docs.sqlalchemy.org/en/20/orm/quickstart.html#declare-models>" %}

{% embed url="<https://docs.sqlalchemy.org/en/20/orm/mapping_styles.html#orm-declarative-mapping>" %}

***

***

***

## <mark style="color:green;">BaseModel</mark>

Default base class for tables models. Subclass of [**DeclarativeBase**](https://docs.sqlalchemy.org/en/20/orm/mapping_api.html#sqlalchemy.orm.DeclarativeBase).

***

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://utca.knowledgator.com/datasources/db/sql.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.
