Changeset 811


Ignore:
Timestamp:
Feb 1, 2016, 4:47:39 AM (4 years ago)
Author:
cito
Message:

Mention get_as_dict() in the tutorial

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/contents/tutorial.rst

    r716 r811  
    6767
    6868Or, you can add a whole bunch of fruits at the same time using the
    69 :meth:`DB.inserttable` method. Note that this method uses the COPY command
    70 of PostgreSQL to insert all data in one operation, which is faster than
    71 sending many INSERT commands::
     69:meth:`Connection.inserttable` method.  Note that this method uses the COPY
     70command of PostgreSQL to insert all data in one batch operation, which is much
     71faster than sending many individual INSERT commands::
    7272
    7373    >>> more_fruits = 'cherimaya durian eggfruit fig grapefruit'.split()
     
    108108    'durian'
    109109
     110Using the method :meth:`DB.get_as_dict`, you can easily import the whole table
     111into a Python dictionary mapping the primary key *id* to the *name*::
     112
     113    >>> db.get_as_dict('fruits', scalar=True)
     114    OrderedDict([(1, 'apple'),
     115                 (2, 'banana'),
     116                 (3, 'cherimaya'),
     117                 (4, 'durian'),
     118                 (5, 'eggfruit'),
     119                 (6, 'fig'),
     120                 (7, 'grapefruit')])
     121
    110122To change a single row in the database, you can use the :meth:`DB.update`
    111123method. For instance, if you want to capitalize the name 'banana'::
Note: See TracChangeset for help on using the changeset viewer.