Skip to content

Commit

Permalink
add mysql flow example
Browse files Browse the repository at this point in the history
  • Loading branch information
tchoedak committed Oct 3, 2020
1 parent 33cb446 commit bc89224
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions examples/task_library/mysql/mysql_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from prefect.tasks.mysql.mysql import MySQLFetch, MySQLExecute
from prefect import Flow, task

EXAMPLE_TABLE = 'user'
HOST = 'localhost'
PORT = 3306
DB_NAME = 'ext'
USER = 'admin'
PASSWORD = 'admin'


mysql_fetch = MySQLFetch(
host=HOST, port=PORT, db_name=DB_NAME, user=USER, password=PASSWORD
)

mysql_exec = MySQLExecute(
host=HOST, port=PORT, db_name=DB_NAME, user=USER, password=PASSWORD
)


@task
def print_results(x):
print(x)


with Flow('MySQL Example') as flow:
# fetch 3 results
fetch_results = mysql_fetch(
query=f'SELECT * FROM {EXAMPLE_TABLE}', fetch='many', fetch_count=3
)
print_results(fetch_results)

# execute a query that returns 3 results
exec_results = mysql_exec(query=f'SELECT * FROM {EXAMPLE_TABLE} LIMIT 3')
print_results(exec_results)


flow.run()

0 comments on commit bc89224

Please sign in to comment.