summaryrefslogtreecommitdiff
path: root/topics
diff options
context:
space:
mode:
authorMunyoki Kilyungi2022-09-30 13:19:20 +0300
committerMunyoki Kilyungi2022-09-30 13:19:20 +0300
commit0b08ecc9812c2bdc58ea8df4f751442f02074e6f (patch)
tree18e4f1fb1431091850daf89ce0deb0576d92f7d6 /topics
parent9db83b180ec72cc23e1384a699092a1ec151ed20 (diff)
downloadgn-gemtext-0b08ecc9812c2bdc58ea8df4f751442f02074e6f.tar.gz
Document passing conn object to sql_query_mdict
* topics/maybe-monad.gmi: Update example snippet.
Diffstat (limited to 'topics')
-rw-r--r--topics/maybe-monad.gmi5
1 files changed, 3 insertions, 2 deletions
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.