prefect_sqlalchemy.database
Tasks for querying a database with SQLAlchemy
Functions
check_make_url
Classes
SqlAlchemyConnector
Block used to manage authentication with a database using synchronous drivers.
Upon instantiating, an engine is created and maintained for the life of
the object until the close method is called.
It is recommended to use this block as a context manager, which will automatically
close the engine and its connections when the context is exited.
It is also recommended that this block is loaded and consumed within a single task
or flow because if the block is passed across separate tasks and flows,
the state of the block’s connection and cursor could be lost.
Attributes:
connection_info: SQLAlchemy URL to create the engine; either create from components or create from a string.connect_args: The options which will be passed directly to the DBAPI’s connect() method as additional keyword arguments.fetch_size: The number of rows to fetch at a time.
block_initialization
close
execute
operation: The SQL query or other operation to be executed.parameters: The parameters for the operation.**execution_options: Options to pass toConnection.execution_options.
execute_many
operation: The SQL query or other operation to be executed.seq_of_parameters: The sequence of parameters for the operation.**execution_options: Options to pass toConnection.execution_options.
fetch_all
operation: The SQL query or other operation to be executed.parameters: The parameters for the operation.**execution_options: Options to pass toConnection.execution_options.
- A list of tuples containing the data returned by the database, where each row is a tuple and each column is a value in the tuple.
fetch_many
operation: The SQL query or other operation to be executed.parameters: The parameters for the operation.size: The number of results to return; if None or 0, uses the value offetch_sizeconfigured on the block.**execution_options: Options to pass toConnection.execution_options.
- A list of tuples containing the data returned by the database, where each row is a tuple and each column is a value in the tuple.
fetch_one
operation: The SQL query or other operation to be executed.parameters: The parameters for the operation.**execution_options: Options to pass toConnection.execution_options.
- A tuple containing the data returned by the database, where each column is a value in the tuple.
get_client
client_type: Select from either ‘engine’ or ‘connection’.**get_client_kwargs: Additional keyword arguments to pass to eitherget_engineorget_connection.
- The authenticated SQLAlchemy engine or connection.
get_connection
begin: Whether to begin a transaction on the connection; if True, if any operations fail, the entire transaction will be rolled back.**connect_kwargs: Additional keyword arguments to pass to eitherengine.beginor engine.connect`.
- The SQLAlchemy Connection.
get_engine
- The authenticated SQLAlchemy Engine.
reset_connections
fetch_* methods return new results.
AsyncSqlAlchemyConnector
Block used to manage authentication with a database using asynchronous drivers.
Upon instantiating, an engine is created and maintained for the life of
the object until the close method is called.
It is recommended to use this block as an async context manager, which will
automatically close the engine and its connections when the context is exited.
It is also recommended that this block is loaded and consumed within a single task
or flow because if the block is passed across separate tasks and flows,
the state of the block’s connection and cursor could be lost.
Attributes:
connection_info: SQLAlchemy URL to create the engine; either create from components or create from a string.connect_args: The options which will be passed directly to the DBAPI’s connect() method as additional keyword arguments.fetch_size: The number of rows to fetch at a time.
block_initialization
close
execute
operation: The SQL query or other operation to be executed.parameters: The parameters for the operation.**execution_options: Options to pass toConnection.execution_options.
execute_many
operation: The SQL query or other operation to be executed.seq_of_parameters: The sequence of parameters for the operation.**execution_options: Options to pass toConnection.execution_options.
fetch_all
operation: The SQL query or other operation to be executed.parameters: The parameters for the operation.**execution_options: Options to pass toConnection.execution_options.
- A list of tuples containing the data returned by the database, where each row is a tuple and each column is a value in the tuple.
fetch_many
operation: The SQL query or other operation to be executed.parameters: The parameters for the operation.size: The number of results to return; if None or 0, uses the value offetch_sizeconfigured on the block.**execution_options: Options to pass toConnection.execution_options.
- A list of tuples containing the data returned by the database, where each row is a tuple and each column is a value in the tuple.
fetch_one
operation: The SQL query or other operation to be executed.parameters: The parameters for the operation.**execution_options: Options to pass toConnection.execution_options.
- A tuple containing the data returned by the database, where each column is a value in the tuple.
get_client
client_type: Select from either ‘engine’ or ‘connection’.**get_client_kwargs: Additional keyword arguments to pass to eitherget_engineorget_connection.
- The authenticated SQLAlchemy engine or connection.
get_connection
begin: Whether to begin a transaction on the connection; if True, if any operations fail, the entire transaction will be rolled back.**connect_kwargs: Additional keyword arguments to pass to eitherengine.beginor engine.connect`.
- The SQLAlchemy AsyncConnection.
get_engine
- The authenticated SQLAlchemy AsyncEngine.
reset_connections
fetch_* methods return new results.