more flexible approach.
- query.order_by() and query.group_by() will accept
- multiple arguments using *args.
+ multiple arguments using *args (like select()
+ already does).
- Fixed/covered case when using a False/0 value as a
polymorphic discriminator.
q = self._no_statement("order_by")
if self._aliases_tail:
- criterion = [expression._literal_as_text(o) for o in util.starargs_as_list(*criterion)]
+ criterion = [expression._literal_as_text(o) for o in criterion]
criterion = self._aliases_tail.adapt_list(criterion)
if q._order_by is False:
- q._order_by = util.starargs_as_list(*criterion)
+ q._order_by = criterion
else:
- q._order_by = q._order_by + util.starargs_as_list(*criterion)
+ q._order_by = q._order_by + criterion
return q
-
+ order_by = util.array_as_starargs_decorator(order_by)
+
def group_by(self, *criterion):
"""apply one or more GROUP BY criterion to the query and return the newly resulting ``Query``"""
q = self._no_statement("group_by")
if q._group_by is False:
- q._group_by = util.starargs_as_list(*criterion)
+ q._group_by = criterion
else:
- q._group_by = q._group_by + util.starargs_as_list(*criterion)
+ q._group_by = q._group_by + criterion
return q
+ group_by = util.array_as_starargs_decorator(group_by)
def having(self, criterion):
"""apply a HAVING criterion to the query and return the newly resulting ``Query``."""
else:
return x
-def starargs_as_list(*args):
- """interpret the given *args as either a list of *args,
- or detect if it's a single list and return that.
+def array_as_starargs_decorator(func):
+ """Interpret a single positional array argument as
+ *args for the decorated method.
"""
- if len(args) == 1:
- return to_list(args[0], [])
- else:
- return list(args)
+ def starargs_as_list(self, *args, **kwargs):
+ if len(args) == 1:
+ return func(self, *to_list(args[0], []), **kwargs)
+ else:
+ return func(self, *args, **kwargs)
+ return starargs_as_list
def to_set(x):
if x is None: