From 52ad64076608787b0b52c864742b19385b276025 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Mon, 24 Apr 2023 14:22:45 +0200 Subject: [PATCH] Add example in readme. --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index d9cbbf1..e3abcf9 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,31 @@ with Flow(...) as flow: close_ssh_tunnel.run(tunnel=tunnel, upstream_tasks=[mysql_closed]) ``` +**Use SQL transactions and dry running** + +```python +from lolafect.connections import connect_to_mysql, close_mysql_connection +from lolafect.utils import begin_sql_transaction, end_sql_transaction + +with Flow(...) as flow: + connection = connect_to_mysql( + mysql_credentials={...}, # You probably want to get this from TEST_LOLACONFIG.DW_CREDENTIALS + ) + transaction_started = begin_sql_transaction(connection) + task_result = some_task_that_needs_mysql( + connection=connection, + upstream_task=[transaction_started] + ) + transaction_finished = end_sql_transaction( + connection, + dry_run=False, # True means rollback, False means commit changes + upstream_tasks=[task_result] + ) + + close_mysql_connection(connection=connection, upstream_tasks=[transaction_finished]) + +``` + ### Use Great Expectations **Run a Great Expectations validation on a MySQL query**