Executesql¶
flowtask.components.ExecuteSQL
¶
ExecuteSQL
¶
Bases: QSSupport, TemplateSupport, FlowComponent
ExecuteSQL
Overview
Executes one or more SQL queries against a PostgreSQL database, also can execute SQL's in a file.
Properties (inherited from FlowComponent)
.. table:: Properties :widths: auto
+--------------+----------+-----------+-------------------------------------------------------+
| Name | Required | Summary |
+--------------+----------+-----------+-------------------------------------------------------+
| skipError | No | The name of the database schema to use (default: ""). |
+--------------+----------+-----------+-------------------------------------------------------+
| sql | No | A raw SQL query string to execute. |
+--------------+----------+-----------+-------------------------------------------------------+
| file_sql | No | A path (string) or list of paths (strings) to SQL files |
| | | containing the queries to execute. |
+--------------+----------+-----------+-------------------------------------------------------+
| pattern | No | A dictionary mapping variable names to functions that return |
| | | the corresponding values to be used in the SQL query. |
+--------------+----------+-----------+-------------------------------------------------------+
| use_template | No | Whether to treat the SQL string as a template and use the |
| | | `_templateparser` component to render it (default: False). |
+--------------+----------+-----------+-------------------------------------------------------+
| multi | No | Whether to treat the `sql` property as a list of multiple |
| | | queries to execute sequentially (default: False). |
+--------------+----------+-----------+-------------------------------------------------------+
| exec_timeout | No | The timeout value for executing a single SQL query |
| | | (default: 3600 seconds). |
+--------------+----------+-----------+-------------------------------------------------------+
Methods
- open_sqlfile(self, file: PurePath, **kwargs) -> str: Opens an SQL file and returns its content.
- get_connection(self, event_loop: asyncio.AbstractEventLoop): Creates a connection pool to the PostgreSQL database.
- _execute(self, query, event_loop): Executes a single SQL query asynchronously.
- execute_sql(self, query: str, event_loop: asyncio.AbstractEventLoop) -> str: Executes an SQL query and returns the result.
Notes
- This component uses asynchronous functions for non-blocking I/O operations.
- Error handling is implemented to catch exceptions during database connection, SQL execution, and file operations.
- Supports loading SQL queries from files.
- Supports using templates for dynamic SQL generation.
-
Supports executing multiple queries sequentially.
Example: