@@ -367,7 +367,7 @@ def run(self, sql, parameters=None, *a, **kw):
367
367
txn .execute (sql , parameters )
368
368
369
369
370
- def one (self , sql , parameters = None , record_type = None , zero = None , \
370
+ def one (self , sql , parameters = None , record_type = None , default = None , \
371
371
* a , ** kw ):
372
372
"""Execute a query and return a single result or a default value.
373
373
@@ -376,13 +376,13 @@ def one(self, sql, parameters=None, record_type=None, zero=None, \
376
376
:type parameters: dict or tuple
377
377
:param record_type: the type of record to return
378
378
:type record_type: type or string
379
- :param zero : the value to return if zero results are found
379
+ :param default : the value to return if no results are found
380
380
:param a: passed through to
381
381
:py:meth:`~postgres.Postgres.get_transaction`
382
382
:param kw: passed through to
383
383
:py:meth:`~postgres.Postgres.get_transaction`
384
- :returns: a single record or value or the value of the :py:attr:`zero`
385
- argument
384
+ :returns: a single record or value or the value of the
385
+ :py:attr:`default` argument
386
386
:raises: :py:exc:`~postgres.TooFew` or :py:exc:`~postgres.TooMany`
387
387
388
388
Use this for the common case where there should only be one record, but
@@ -399,16 +399,16 @@ def one(self, sql, parameters=None, record_type=None, zero=None, \
399
399
...
400
400
No blam yet.
401
401
402
- If you pass :py:attr:`zero ` we'll return that instead of
402
+ If you pass :py:attr:`default ` we'll return that instead of
403
403
:py:class:`None`:
404
404
405
- >>> db.one("SELECT * FROM foo WHERE bar='blam'", zero =False)
405
+ >>> db.one("SELECT * FROM foo WHERE bar='blam'", default =False)
406
406
False
407
407
408
408
We specifically don't support passing lambdas or other callables for
409
- the :py:attr:`zero ` parameter. That gets complicated quickly, and it's
410
- easy to just check the return value in the caller and do your extra
411
- logic there.
409
+ the :py:attr:`default ` parameter. That gets complicated quickly, and
410
+ it's easy to just check the return value in the caller and do your
411
+ extra logic there.
412
412
413
413
You can use :py:attr:`record_type` to override the type associated with
414
414
the default :py:attr:`cursor_factory` for your
@@ -442,17 +442,17 @@ def one(self, sql, parameters=None, record_type=None, zero=None, \
442
442
42
443
443
444
444
And if the dereferenced value is :py:class:`None`, we return the value
445
- of :py:attr:`zero `:
445
+ of :py:attr:`default `:
446
446
447
- >>> db.one("SELECT sum(baz) FROM foo WHERE bar='nope'", zero =0)
447
+ >>> db.one("SELECT sum(baz) FROM foo WHERE bar='nope'", default =0)
448
448
0
449
449
450
450
Dereferencing will use :py:meth:`.values` if it exists on the record,
451
451
so it should work for both mappings and sequences.
452
452
453
453
>>> db.one( "SELECT sum(baz) FROM foo WHERE bar='nope'"
454
454
... , record_type=dict
455
- ... , zero =0
455
+ ... , default =0
456
456
... )
457
457
0
458
458
@@ -465,9 +465,9 @@ def one(self, sql, parameters=None, record_type=None, zero=None, \
465
465
seq = list (out .values ()) if hasattr (out , 'values' ) else out
466
466
out = seq [0 ]
467
467
468
- # zero
468
+ # default
469
469
if out is None :
470
- out = zero
470
+ out = default
471
471
472
472
return out
473
473
0 commit comments