3535 {'bar': 'baz'}
3636
3737
38- Use :py:meth:`~postgres.Postgres.rows ` to fetch all results:
38+ Use :py:meth:`~postgres.Postgres.all ` to fetch all results:
3939
40- >>> db.rows ("SELECT * FROM foo ORDER BY bar")
40+ >>> db.all ("SELECT * FROM foo ORDER BY bar")
4141 [{'bar': 'baz'}, {'bar': 'buz'}]
4242
4343
6464
6565Eighty percent of your database usage should be covered by the simple
6666: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%,
6868:py:mod:`postgres` provides context managers for working at increasingly lower
6969levels of abstraction. The lowest level of abstraction in :py:mod:`postgres` is
7070a :py:mod:`psycopg2` `connection pool
100100
101101 >>> with db.get_transaction() as txn:
102102 ... 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")
104104 ...
105105 [{'bar': 'baz'}, {'bar': 'buz'}]
106- >>> db.rows ("SELECT * FROM foo ORDER BY bar")
106+ >>> db.all ("SELECT * FROM foo ORDER BY bar")
107107 [{'bar': 'baz'}, {'bar': 'blam'}, {'bar': 'buz'}]
108108
109109The :py:func:`~postgres.Postgres.get_transaction` manager gives you a cursor
@@ -237,7 +237,7 @@ class Postgres(object):
237237 :py:class:`NamedTupleCursor`.
238238
239239 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 `,
241241 were chosen to be short and memorable, and to not conflict with the DB-API
242242 2.0 :py:meth:`execute`, :py:meth:`fetchone`, and :py:meth:`fetchall`
243243 methods, which have slightly different semantics (under DB-API 2.0 you call
@@ -249,7 +249,7 @@ class Postgres(object):
249249 Note that when working inside a block under one of the context managers,
250250 you're using DB-API 2.0 (:py:meth:`execute` + :py:meth:`fetch*`), not our
251251 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 `).
253253
254254 .. _this ticket: https://github.com/gittip/postgres.py/issues/16
255255
@@ -332,15 +332,15 @@ def one(self, sql, parameters=None, strict=None):
332332
333333 return cursor .fetchone ()
334334
335- def rows (self , sql , parameters = None ):
335+ def all (self , sql , parameters = None ):
336336 """Execute a query and return all resulting rows.
337337
338338 :param unicode sql: the SQL statement to execute
339339 :param parameters: the bind parameters for the SQL statement
340340 :type parameters: dict or tuple
341341 :returns: :py:class:`list` of rows
342342
343- >>> for row in db.rows ("SELECT bar FROM foo"):
343+ >>> for row in db.all ("SELECT bar FROM foo"):
344344 ... print(row["bar"])
345345 ...
346346 baz
@@ -351,13 +351,21 @@ def rows(self, sql, parameters=None):
351351 cursor .execute (sql , parameters )
352352 return cursor .fetchall ()
353353
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+
354362 def get_cursor (self , * a , ** kw ):
355363 """Return a :py:class:`~postgres.CursorContextManager` that uses our
356364 connection pool.
357365
358366 This is what :py:meth:`~postgres.Postgres.run`,
359367 :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
361369 use it if you want to access `cursor attributes
362370 <http://initd.org/psycopg/docs/cursor.html>`_, for example.
363371
0 commit comments