35
35
{'bar': 'baz'}
36
36
37
37
38
- Use :py:meth:`~postgres.Postgres.rows ` to fetch all results:
38
+ Use :py:meth:`~postgres.Postgres.all ` to fetch all results:
39
39
40
- >>> db.rows ("SELECT * FROM foo ORDER BY bar")
40
+ >>> db.all ("SELECT * FROM foo ORDER BY bar")
41
41
[{'bar': 'baz'}, {'bar': 'buz'}]
42
42
43
43
64
64
65
65
Eighty percent of your database usage should be covered by the simple
66
66
:py:meth:`~postgres.Postgres.run`, :py:meth:`~postgres.Postgres.one`,
67
- :py:meth:`~postgres.Postgres.rows ` API introduced above. For the other 20%,
67
+ :py:meth:`~postgres.Postgres.all ` API introduced above. For the other 20%,
68
68
:py:mod:`postgres` provides context managers for working at increasingly lower
69
69
levels of abstraction. The lowest level of abstraction in :py:mod:`postgres` is
70
70
a :py:mod:`psycopg2` `connection pool
100
100
101
101
>>> with db.get_transaction() as txn:
102
102
... txn.execute("INSERT INTO foo VALUES ('blam')")
103
- ... db.rows ("SELECT * FROM foo ORDER BY bar")
103
+ ... db.all ("SELECT * FROM foo ORDER BY bar")
104
104
...
105
105
[{'bar': 'baz'}, {'bar': 'buz'}]
106
- >>> db.rows ("SELECT * FROM foo ORDER BY bar")
106
+ >>> db.all ("SELECT * FROM foo ORDER BY bar")
107
107
[{'bar': 'baz'}, {'bar': 'blam'}, {'bar': 'buz'}]
108
108
109
109
The :py:func:`~postgres.Postgres.get_transaction` manager gives you a cursor
@@ -237,7 +237,7 @@ class Postgres(object):
237
237
:py:class:`NamedTupleCursor`.
238
238
239
239
The names in our simple API, :py:meth:`~postgres.Postgres.run`,
240
- :py:meth:`~postgres.Postgres.one`, and :py:meth:`~postgres.Postgres.rows `,
240
+ :py:meth:`~postgres.Postgres.one`, and :py:meth:`~postgres.Postgres.all `,
241
241
were chosen to be short and memorable, and to not conflict with the DB-API
242
242
2.0 :py:meth:`execute`, :py:meth:`fetchone`, and :py:meth:`fetchall`
243
243
methods, which have slightly different semantics (under DB-API 2.0 you call
@@ -249,7 +249,7 @@ class Postgres(object):
249
249
Note that when working inside a block under one of the context managers,
250
250
you're using DB-API 2.0 (:py:meth:`execute` + :py:meth:`fetch*`), not our
251
251
simple API (:py:meth:`~postgres.Postgres.run` /
252
- :py:meth:`~postgres.Postgres.one` / :py:meth:`~postgres.Postgres.rows `).
252
+ :py:meth:`~postgres.Postgres.one` / :py:meth:`~postgres.Postgres.all `).
253
253
254
254
.. _this ticket: https://github.com/gittip/postgres.py/issues/16
255
255
@@ -332,15 +332,15 @@ def one(self, sql, parameters=None, strict=None):
332
332
333
333
return cursor .fetchone ()
334
334
335
- def rows (self , sql , parameters = None ):
335
+ def all (self , sql , parameters = None ):
336
336
"""Execute a query and return all resulting rows.
337
337
338
338
:param unicode sql: the SQL statement to execute
339
339
:param parameters: the bind parameters for the SQL statement
340
340
:type parameters: dict or tuple
341
341
:returns: :py:class:`list` of rows
342
342
343
- >>> for row in db.rows ("SELECT bar FROM foo"):
343
+ >>> for row in db.all ("SELECT bar FROM foo"):
344
344
... print(row["bar"])
345
345
...
346
346
baz
@@ -351,13 +351,21 @@ def rows(self, sql, parameters=None):
351
351
cursor .execute (sql , parameters )
352
352
return cursor .fetchall ()
353
353
354
+ def rows (self , * a , ** kw ):
355
+
356
+ # This is for backwards compatibility, see #16. It is stubbed instead
357
+ # of aliased to avoid showing up in our docs via sphinx autodoc.
358
+
359
+ return self .all (* a , ** kw )
360
+
361
+
354
362
def get_cursor (self , * a , ** kw ):
355
363
"""Return a :py:class:`~postgres.CursorContextManager` that uses our
356
364
connection pool.
357
365
358
366
This is what :py:meth:`~postgres.Postgres.run`,
359
367
:py:meth:`~postgres.Postgres.one`, and
360
- :py:meth:`~postgres.Postgres.rows ` use under the hood. You might
368
+ :py:meth:`~postgres.Postgres.all ` use under the hood. You might
361
369
use it if you want to access `cursor attributes
362
370
<http://initd.org/psycopg/docs/cursor.html>`_, for example.
363
371
0 commit comments