Changeset 767


Ignore:
Timestamp:
Jan 19, 2016, 5:51:40 AM (4 years ago)
Author:
cito
Message:

Recommend use as context manager in docs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/contents/pg/db_wrapper.rst

    r765 r767  
    66.. class:: DB
    77
    8 The :class:`Connection` methods are wrapped in the class :class:`DB`.
     8The :class:`Connection` methods are wrapped in the class :class:`DB`
     9which also adds convenient higher level methods for working with the
     10database.  It also serves as a context manager for the connection.
    911The preferred way to use this module is as follows::
    1012
    1113    import pg
    1214
    13     db = pg.DB(...)  # see below
    14 
    15     for r in db.query(  # just for example
    16         """SELECT foo,bar
    17          FROM foo_bar_table
    18          WHERE foo !~ bar"""
    19         ).dictresult():
    20 
    21         print '%(foo)s %(bar)s' % r
     15    with pg.DB(...) as db:  # for parameters, see below
     16        for r in db.query(  # just for example
     17                "SELECT foo, bar FROM foo_bar_table WHERE foo !~ bar"
     18                ).dictresult():
     19            print('%(foo)s %(bar)s' % r)
    2220
    2321This class can be subclassed as in this example::
Note: See TracChangeset for help on using the changeset viewer.