Skip to content

Commit

Permalink
Added ability to easily pipe functions after initial function definit…
Browse files Browse the repository at this point in the history
…ion using "|" operator.
  • Loading branch information
vmagamedov committed Mar 13, 2014
1 parent 44ac89c commit a4dcf39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sqlconstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ class _Processable(object):
def __processor__(self, scope):
raise NotImplementedError

def __or__(self, value):
return apply_(value, [self])


def _get_value_processor(scope, value):
if isinstance(value, ColumnElement):
Expand Down
10 changes: 10 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,16 @@ def test_defined_calls(self):
(1 + 2 + 3, 'foo' + 'bar' + 'baz'),
)

def test_pipe_operator(self):
struct = Construct({
'a_name_hash': apply_(capitalize, [self.a_cls.name]) | hash,
})

s1, s2 = self.session.query(struct).order_by(self.a_cls.name).all()

self.assertEqual(s1.a_name_hash, hash('A1'))
self.assertEqual(s2.a_name_hash, hash('A2'))

def test_query_count(self):
query = self.session.query(
Construct({'a_id': self.a_cls.id,
Expand Down

0 comments on commit a4dcf39

Please sign in to comment.