Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changing set_alias to alias

  • Loading branch information...
commit b44cfd601f61b7492da8baed1f73297978df1e2f 1 parent 32860e5
Charles Leifer authored
Showing with 19 additions and 19 deletions.
  1. +8 −8 peewee.py
  2. +7 −7 playhouse/tests_postgres.py
  3. +4 −4 tests.py
16 peewee.py
View
@@ -183,10 +183,10 @@ def clone(self):
class Expr(object):
def __init__(self):
- self.alias = None
+ self._alias = None
- def set_alias(self, a=None):
- self.alias = a
+ def alias(self, a=None):
+ self._alias = a
return self
def asc(self):
@@ -616,8 +616,8 @@ def quote(self, s):
return ''.join((self.quote_char, s, self.quote_char))
def _add_alias(self, expr_str, expr):
- if expr.alias:
- expr_str = ' '.join((expr_str, 'AS', expr.alias))
+ if expr._alias:
+ expr_str = ' '.join((expr_str, 'AS', expr._alias))
return expr_str
def _max_alias(self, am):
@@ -984,8 +984,8 @@ def construct_instance(self, row):
if isinstance(expr, Field):
setattr(instance, expr.name, expr.python_value(value))
- elif isinstance(expr, Expr) and expr.alias:
- setattr(instance, expr.alias, value)
+ elif isinstance(expr, Expr) and expr._alias:
+ setattr(instance, expr._alias, value)
else:
setattr(instance, cols[i], value)
@@ -1295,7 +1295,7 @@ def naive(self, naive=True):
self._naive = naive
def annotate(self, rel_model, annotation=None):
- annotation = annotation or fn.Count(rel_model._meta.primary_key).set_alias('count')
+ annotation = annotation or fn.Count(rel_model._meta.primary_key).alias('count')
query = self.clone()
query = query.ensure_join(query._query_ctx, rel_model)
if not query._group_by:
14 playhouse/tests_postgres.py
View
@@ -44,41 +44,41 @@ def test_storage(self):
def test_selecting(self):
self.create()
- sq = Testing.select(Testing.name, Testing.data.keys().set_alias('keys'))
+ sq = Testing.select(Testing.name, Testing.data.keys().alias('keys'))
self.assertEqual([(x.name, sorted(x.keys)) for x in sq], [
('t1', ['k1', 'k2']), ('t2', ['k2', 'k3'])
])
- sq = Testing.select(Testing.name, Testing.data.values().set_alias('vals'))
+ sq = Testing.select(Testing.name, Testing.data.values().alias('vals'))
self.assertEqual([(x.name, sorted(x.vals)) for x in sq], [
('t1', ['v1', 'v2']), ('t2', ['v2', 'v3'])
])
- sq = Testing.select(Testing.name, Testing.data.items().set_alias('mtx'))
+ sq = Testing.select(Testing.name, Testing.data.items().alias('mtx'))
self.assertEqual([(x.name, sorted(x.mtx)) for x in sq], [
('t1', [['k1', 'v1'], ['k2', 'v2']]),
('t2', [['k2', 'v2'], ['k3', 'v3']]),
])
- sq = Testing.select(Testing.name, Testing.data.slice('k2', 'k3').set_alias('kz'))
+ sq = Testing.select(Testing.name, Testing.data.slice('k2', 'k3').alias('kz'))
self.assertEqual([(x.name, x.kz) for x in sq], [
('t1', {'k2': 'v2'}),
('t2', {'k2': 'v2', 'k3': 'v3'}),
])
- sq = Testing.select(Testing.name, Testing.data.slice('k4').set_alias('kz'))
+ sq = Testing.select(Testing.name, Testing.data.slice('k4').alias('kz'))
self.assertEqual([(x.name, x.kz) for x in sq], [
('t1', {}),
('t2', {}),
])
- sq = Testing.select(Testing.name, Testing.data.exists('k3').set_alias('ke'))
+ sq = Testing.select(Testing.name, Testing.data.exists('k3').alias('ke'))
self.assertEqual([(x.name, x.ke) for x in sq], [
('t1', False),
('t2', True),
])
- sq = Testing.select(Testing.name, Testing.data.defined('k3').set_alias('ke'))
+ sq = Testing.select(Testing.name, Testing.data.defined('k3').alias('ke'))
self.assertEqual([(x.name, x.ke) for x in sq], [
('t1', False),
('t2', True),
8 tests.py
View
@@ -282,7 +282,7 @@ def test_selection(self):
sq = SelectQuery(Blog, Blog.pk, Blog.title, Blog.user, User.username).join(User)
self.assertSelect(sq, 'blog."pk", blog."title", blog."user_id", users."username"', [])
- sq = SelectQuery(User, fn.Lower(fn.Substr(User.username, 0, 1)).set_alias('lu'), fn.Count(Blog.pk)).join(Blog)
+ sq = SelectQuery(User, fn.Lower(fn.Substr(User.username, 0, 1)).alias('lu'), fn.Count(Blog.pk)).join(Blog)
self.assertSelect(sq, 'Lower(Substr(users."username", ?, ?)) AS lu, Count(blog."pk")', [0, 1])
sq = SelectQuery(User, User.username, fn.Count(Blog.select().where(Blog.user == User.id)))
@@ -462,7 +462,7 @@ def test_ordering(self):
sq = SelectQuery(User).join(Blog).order_by(User.username.desc(), Blog.title.asc())
self.assertOrderBy(sq, 'users."username" DESC, blog."title" ASC', [])
- base_sq = SelectQuery(User, User.username, fn.Count(Blog.pk).set_alias('count')).join(Blog).group_by(User.username)
+ base_sq = SelectQuery(User, User.username, fn.Count(Blog.pk).alias('count')).join(Blog).group_by(User.username)
sq = base_sq.order_by(fn.Count(Blog.pk).desc())
self.assertOrderBy(sq, 'Count(blog."pk") DESC', [])
@@ -567,13 +567,13 @@ def test_annotate(self):
self.assertWhere(sq, '', [])
self.assertGroupBy(sq, 'users."id", users."username"', [])
- sq = User.select(User.username).annotate(Blog, fn.Sum(Blog.pk).set_alias('sum')).where(User.username == 'foo')
+ sq = User.select(User.username).annotate(Blog, fn.Sum(Blog.pk).alias('sum')).where(User.username == 'foo')
self.assertSelect(sq, 'users."username", Sum(blog."pk") AS sum', [])
self.assertJoins(sq, ['INNER JOIN "blog" AS blog ON users."id" = blog."user_id"'])
self.assertWhere(sq, 'users."username" = ?', ['foo'])
self.assertGroupBy(sq, 'users."username"', [])
- sq = User.select(User.username).annotate(Blog).annotate(Blog, fn.Max(Blog.pk).set_alias('mx'))
+ sq = User.select(User.username).annotate(Blog).annotate(Blog, fn.Max(Blog.pk).alias('mx'))
self.assertSelect(sq, 'users."username", Count(blog."pk") AS count, Max(blog."pk") AS mx', [])
self.assertJoins(sq, ['INNER JOIN "blog" AS blog ON users."id" = blog."user_id"'])
self.assertWhere(sq, '', [])
Please sign in to comment.
Something went wrong with that request. Please try again.