Hello community, here is the log from the commit of package python-python-sql for openSUSE:Factory checked in at 2020-01-27 20:16:59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-python-sql (Old) and /work/SRC/openSUSE:Factory/.python-python-sql.new.26092 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-python-sql" Mon Jan 27 20:16:59 2020 rev:4 rq:767572 version:1.1.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-python-sql/python-python-sql.changes 2018-10-04 19:01:37.535195100 +0200 +++ /work/SRC/openSUSE:Factory/.python-python-sql.new.26092/python-python-sql.changes 2020-01-27 20:16:59.320506081 +0100 @@ -1,0 +2,8 @@ +Sat Jan 25 18:30:16 UTC 2020 - Axel Braun <[email protected]> + +- Version 1.1.0 - 2020-01-25 + * Add ORDER BY clause to aggregate functions + * Add support for Python 3.8 + * Add distinct on Select + +------------------------------------------------------------------- Old: ---- python-sql-1.0.0.tar.gz New: ---- python-sql-1.1.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-python-sql.spec ++++++ --- /var/tmp/diff_new_pack.jvch0a/_old 2020-01-27 20:17:00.064506535 +0100 +++ /var/tmp/diff_new_pack.jvch0a/_new 2020-01-27 20:17:00.076506542 +0100 @@ -19,7 +19,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} %define base_name python-sql Name: python-%{base_name} -Version: 1.0.0 +Version: 1.1.0 Release: 0 Summary: Library to write SQL queries License: BSD-3-Clause ++++++ python-sql-1.0.0.tar.gz -> python-sql-1.1.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-sql-1.0.0/.drone.yml new/python-sql-1.1.0/.drone.yml --- old/python-sql-1.0.0/.drone.yml 2018-08-18 13:25:33.000000000 +0200 +++ new/python-sql-1.1.0/.drone.yml 2019-12-26 10:47:34.000000000 +0100 @@ -1,6 +1,10 @@ clone: hg: image: plugins/hg + environment: + - HG_SHARE_POOL=/root/.cache/hg + volumes: + - cache:/root/.cache pipeline: tox: @@ -9,7 +13,7 @@ - pip install tox - tox -e "${TOXENV}" volumes: - - cache:/root/.cache + - cache:/root/.cache matrix: include: @@ -23,6 +27,8 @@ TOXENV: py36 - IMAGE: python:3.7 TOXENV: py37 + - IMAGE: python:3.8 + TOXENV: py38 - IMAGE: pypy:2 TOXENV: pypy - IMAGE: pypy:3 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-sql-1.0.0/.hgtags new/python-sql-1.1.0/.hgtags --- old/python-sql-1.0.0/.hgtags 2018-09-30 14:27:13.000000000 +0200 +++ new/python-sql-1.1.0/.hgtags 2020-01-25 11:11:52.000000000 +0100 @@ -8,3 +8,4 @@ 5ef77ab47a7bdaaf568ae1c5b3f1b0698ee2418c 0.8 e3bdeb99dd975024e30d8af18c324a0a7f860e63 0.9 7459778aa23150aa6ac39356621c29d368ae1f36 1.0.0 +194182e5b0e2dc6486a32778860f29c80c0672f9 1.1.0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-sql-1.0.0/CHANGELOG new/python-sql-1.1.0/CHANGELOG --- old/python-sql-1.0.0/CHANGELOG 2018-09-30 14:26:46.000000000 +0200 +++ new/python-sql-1.1.0/CHANGELOG 2020-01-25 11:04:49.000000000 +0100 @@ -1,3 +1,8 @@ +Version 1.1.0 - 2020-01-25 +* Add ORDER BY clause to aggregate functions +* Add support for Python 3.8 +* Add distinct on Select + Version 1.0.0 - 2018-09-30 * Add Flavor filter_ to fallback to case expression * Allow to use expression in AtTimeZone diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-sql-1.0.0/PKG-INFO new/python-sql-1.1.0/PKG-INFO --- old/python-sql-1.0.0/PKG-INFO 2018-09-30 14:27:57.000000000 +0200 +++ new/python-sql-1.1.0/PKG-INFO 2020-01-25 11:12:36.000000000 +0100 @@ -1,12 +1,11 @@ Metadata-Version: 1.1 Name: python-sql -Version: 1.0.0 +Version: 1.1.0 Summary: Library to write SQL queries Home-page: http://python-sql.tryton.org/ Author: Tryton Author-email: [email protected] License: BSD -Description-Content-Type: UNKNOWN Description: python-sql ========== @@ -36,6 +35,10 @@ >>> tuple(select) ('SELECT COUNT(%s) FROM "user" AS "a"', (1,)) + >>> select = user.select(user.name, distinct=True) + >>> tuple(select) + ('SELECT DISTINCT "a"."name" FROM "user" AS "a"', ()) + >>> select = user.select(user.id, user.name) >>> tuple(select) ('SELECT "a"."id", "a"."name" FROM "user" AS "a"', ()) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-sql-1.0.0/README new/python-sql-1.1.0/README --- old/python-sql-1.0.0/README 2018-08-18 13:25:33.000000000 +0200 +++ new/python-sql-1.1.0/README 2019-11-11 18:46:20.000000000 +0100 @@ -27,6 +27,10 @@ >>> tuple(select) ('SELECT COUNT(%s) FROM "user" AS "a"', (1,)) + >>> select = user.select(user.name, distinct=True) + >>> tuple(select) + ('SELECT DISTINCT "a"."name" FROM "user" AS "a"', ()) + >>> select = user.select(user.id, user.name) >>> tuple(select) ('SELECT "a"."id", "a"."name" FROM "user" AS "a"', ()) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-sql-1.0.0/python_sql.egg-info/PKG-INFO new/python-sql-1.1.0/python_sql.egg-info/PKG-INFO --- old/python-sql-1.0.0/python_sql.egg-info/PKG-INFO 2018-09-30 14:27:57.000000000 +0200 +++ new/python-sql-1.1.0/python_sql.egg-info/PKG-INFO 2020-01-25 11:12:35.000000000 +0100 @@ -1,12 +1,11 @@ Metadata-Version: 1.1 Name: python-sql -Version: 1.0.0 +Version: 1.1.0 Summary: Library to write SQL queries Home-page: http://python-sql.tryton.org/ Author: Tryton Author-email: [email protected] License: BSD -Description-Content-Type: UNKNOWN Description: python-sql ========== @@ -36,6 +35,10 @@ >>> tuple(select) ('SELECT COUNT(%s) FROM "user" AS "a"', (1,)) + >>> select = user.select(user.name, distinct=True) + >>> tuple(select) + ('SELECT DISTINCT "a"."name" FROM "user" AS "a"', ()) + >>> select = user.select(user.id, user.name) >>> tuple(select) ('SELECT "a"."id", "a"."name" FROM "user" AS "a"', ()) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-sql-1.0.0/sql/__init__.py new/python-sql-1.1.0/sql/__init__.py --- old/python-sql-1.0.0/sql/__init__.py 2018-09-30 14:25:27.000000000 +0200 +++ new/python-sql-1.1.0/sql/__init__.py 2020-01-25 11:03:48.000000000 +0100 @@ -35,7 +35,7 @@ from collections import defaultdict from itertools import chain -__version__ = '1.0.0' +__version__ = '1.1.0' __all__ = ['Flavor', 'Table', 'Values', 'Literal', 'Column', 'Join', 'Asc', 'Desc', 'NullsFirst', 'NullsLast', 'format2numeric'] @@ -390,17 +390,20 @@ class Select(FromItem, SelectQuery): __slots__ = ('_columns', '_where', '_group_by', '_having', '_for_', - 'from_', '_distinct_on') + 'from_', '_distinct', '_distinct_on') def __init__(self, columns, from_=None, where=None, group_by=None, - having=None, for_=None, distinct_on=None, **kwargs): - self._distinct_on = None + having=None, for_=None, distinct=False, distinct_on=None, + **kwargs): + self._distinct = False + self._distinct_on = [] self._columns = None self._where = None self._group_by = None self._having = None self._for_ = None super(Select, self).__init__(**kwargs) + self.distinct = distinct self.distinct_on = distinct_on self.columns = columns self.from_ = from_ @@ -410,6 +413,14 @@ self.for_ = for_ @property + def distinct(self): + return bool(self._distinct or self._distinct_on) + + @distinct.setter + def distinct(self, value): + self._distinct = bool(value) + + @property def distinct_on(self): return self._distinct_on @@ -557,11 +568,13 @@ from_ = ' FROM %s' % self.from_ else: from_ = '' - if self.distinct_on is not None: - distinct_on = ('DISTINCT ON (%s) ' - % ', '.join(map(str, self.distinct_on))) + if self.distinct: + distinct = 'DISTINCT ' + if self.distinct_on: + distinct += ('ON (%s) ' + % ', '.join(map(str, self.distinct_on))) else: - distinct_on = '' + distinct = '' if self.columns: columns = ', '.join(map(self._format_column, self.columns)) else: @@ -584,7 +597,7 @@ if self.for_ is not None: for_ = ' ' + ' '.join(map(str, self.for_)) return (self._with_str() - + 'SELECT %s%s%s' % (distinct_on, columns, from_) + + 'SELECT %s%s%s' % (distinct, columns, from_) + where + group_by + having + window + self._order_by_str + self._limit_offset_str + for_) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-sql-1.0.0/sql/aggregate.py new/python-sql-1.1.0/sql/aggregate.py --- old/python-sql-1.0.0/sql/aggregate.py 2018-08-18 13:25:33.000000000 +0200 +++ new/python-sql-1.1.0/sql/aggregate.py 2020-01-18 00:21:28.000000000 +0100 @@ -34,15 +34,16 @@ class Aggregate(Expression): - __slots__ = ('expression', '_distinct', '_within', '_filter', '_window') + __slots__ = ('expression', '_distinct', '_order_by', '_within', + '_filter', '_window') _sql = '' - def __init__(self, expression, distinct=False, within=None, filter_=None, - window=None): - # TODO order_by + def __init__(self, expression, distinct=False, order_by=None, within=None, + filter_=None, window=None): super(Aggregate, self).__init__() self.expression = expression self.distinct = distinct + self.order_by = order_by self.within = within self.filter_ = filter_ self.window = window @@ -57,6 +58,18 @@ self._distinct = value @property + def order_by(self): + return self._order_by + + @order_by.setter + def order_by(self, value): + if value is not None: + if isinstance(value, Expression): + value = [value] + assert all(isinstance(col, Expression) for col in value) + self._order_by = value + + @property def within(self): return self._within @@ -100,7 +113,11 @@ if self.filter_ and not has_filter: from sql.conditionals import Case expression = Case((self.filter_, self._case_expression)) - aggregate = '%s(%s%s)' % (self._sql, quantifier, expression) + order_by = '' + if self.order_by: + order_by = ' ORDER BY %s' % ', '.join(map(str, self.order_by)) + aggregate = '%s(%s%s%s)' % ( + self._sql, quantifier, expression, order_by) within = '' if self.within: within = (' WITHIN GROUP (ORDER BY %s)' @@ -122,6 +139,9 @@ p.extend(self._case_expression.params) else: p.extend(self.expression.params) + if self.order_by: + for expression in self.order_by: + p.extend(expression.params) if self.within: for expression in self.within: p.extend(expression.params) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-sql-1.0.0/sql/tests/test_aggregate.py new/python-sql-1.1.0/sql/tests/test_aggregate.py --- old/python-sql-1.0.0/sql/tests/test_aggregate.py 2018-08-18 13:25:33.000000000 +0200 +++ new/python-sql-1.1.0/sql/tests/test_aggregate.py 2020-01-18 00:21:28.000000000 +0100 @@ -42,6 +42,17 @@ avg = Avg(self.table.a + self.table.b) self.assertEqual(str(avg), 'AVG(("a" + "b"))') + def test_order_by_one_column(self): + avg = Avg(self.table.a, order_by=self.table.b) + self.assertEqual(str(avg), 'AVG("a" ORDER BY "b")') + self.assertEqual(avg.params, ()) + + def test_order_by_multiple_columns(self): + avg = Avg( + self.table.a, order_by=[self.table.b.asc, self.table.c.desc]) + self.assertEqual(str(avg), 'AVG("a" ORDER BY "b" ASC, "c" DESC)') + self.assertEqual(avg.params, ()) + def test_within(self): avg = Avg(self.table.a, within=self.table.b) self.assertEqual(str(avg), 'AVG("a") WITHIN GROUP (ORDER BY "b")') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-sql-1.0.0/sql/tests/test_select.py new/python-sql-1.1.0/sql/tests/test_select.py --- old/python-sql-1.0.0/sql/tests/test_select.py 2018-08-18 13:25:33.000000000 +0200 +++ new/python-sql-1.1.0/sql/tests/test_select.py 2019-11-07 13:56:08.000000000 +0100 @@ -74,6 +74,12 @@ self.assertEqual(str(query), 'SELECT (SELECT %s) AS "foo"') self.assertEqual(query.params, (1,)) + def test_select_distinct(self): + query = self.table.select(self.table.c, distinct=True) + self.assertEqual( + str(query), 'SELECT DISTINCT "a"."c" FROM "t" AS "a"') + self.assertEqual(query.params, ()) + def test_select_distinct_on(self): query = self.table.select(self.table.c, distinct_on=self.table.c) self.assertEqual( diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/python-sql-1.0.0/tox.ini new/python-sql-1.1.0/tox.ini --- old/python-sql-1.0.0/tox.ini 2018-08-18 13:25:33.000000000 +0200 +++ new/python-sql-1.1.0/tox.ini 2019-12-26 10:47:34.000000000 +0100 @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py26, py27, py33, py34, py35, py36, py37, pypy, pypy3, jython +envlist = py26, py27, py33, py34, py35, py36, py37, py38, pypy, pypy3, jython [testenv] commands = {envpython} setup.py test
