Skip to content

Commit

Permalink
Allow columnfactory to accept item-style lookups.
Browse files Browse the repository at this point in the history
Fixes #2776
  • Loading branch information
coleifer committed Sep 11, 2023
1 parent 2ed7181 commit fda81ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions peewee.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ def __init__(self, node):

def __getattr__(self, attr):
return Column(self.node, attr)
__getitem__ = __getattr__


class _DynamicColumn(object):
Expand Down
8 changes: 8 additions & 0 deletions tests/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def test_select(self):
'FROM "users" AS "t1" '
'WHERE ("t1"."username" = ?)'), ['foo'])

query = (User
.select(User.c['id'], User.c['username'])
.where(User.c['username'] == 'test'))
self.assertSQL(query, (
'SELECT "t1"."id", "t1"."username" '
'FROM "users" AS "t1" '
'WHERE ("t1"."username" = ?)'), ['test'])

def test_select_extend(self):
query = User.select(User.c.id, User.c.username)
self.assertSQL(query, (
Expand Down

0 comments on commit fda81ca

Please sign in to comment.