From 0b08ecc9812c2bdc58ea8df4f751442f02074e6f Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Fri, 30 Sep 2022 13:19:20 +0300 Subject: Document passing conn object to sql_query_mdict * topics/maybe-monad.gmi: Update example snippet. --- topics/maybe-monad.gmi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'topics') diff --git a/topics/maybe-monad.gmi b/topics/maybe-monad.gmi index dc3e0b7..b748ad5 100644 --- a/topics/maybe-monad.gmi +++ b/topics/maybe-monad.gmi @@ -45,8 +45,9 @@ with conn.cursor(MySQLdb.cursors.DictCursor) as cursor: ``` But, with sql_query_mdict, the row object is a MonadictDict where all values are monadic. We therefore do not need any special conditional checks. ``` -for row in sql_query_mdict("SELECT foo FROM bar"): - row["foo"].bind(print) +with database_connection() as conn + for row in sql_query_mdict(conn, "SELECT foo FROM bar"): + row["foo"].bind(print) ``` As a bonus, sql_query_mdict also gets rid of cursors by returning a generator and letting us iterate over it pythonically. -- cgit v1.2.3