Commits

Mike Bayer committed 2e4a2ea

- added op() operator to instrumented attributes; i.e.
User.name.op('ilike')('%somename%') [ticket:767]

  • Participants
  • Parent commits 26aff0d

Comments (0)

Files changed (4)

     "attribute_names", a list of individual attribute keynames to be refreshed
     or expired, allowing partial reloads of attributes on an already-loaded 
     instance. [ticket:802]
+  
+  - added op() operator to instrumented attributes; i.e. 
+    User.name.op('ilike')('%somename%') [ticket:767]
     
   - Mapped classes may now define __eq__, __hash__, and __nonzero__ methods
     with arbitrary semantics.  The orm now handles all mapped instances on

lib/sqlalchemy/sql/expression.py

 
     def __invert__(self):
         return self.operate(operators.inv)
-
+    
+    def op(self, opstring):
+        def op(b):
+            return self.operate(operators.op, opstring, b)
+        return op
+        
     def clause_element(self):
         raise NotImplementedError()
 

lib/sqlalchemy/sql/operators.py

 def isnot():
     raise NotImplementedError()
 
+def op(a, opstring, b):
+    return a.op(opstring)(b)
+
 def like_op(a, b):
     return a.like(b)
 

test/orm/query.py

                              "\n'" + compiled + "'\n does not match\n'" +
                              fwd_sql + "'\n or\n'" + rev_sql + "'")
 
+    def test_op(self):
+        assert str(User.name.op('ilike')('17').compile(dialect=default.DefaultDialect())) == "users.name ilike :users_name"
+        
     def test_in(self):
          self._test(User.id.in_(['a', 'b']),
                     "users.id IN (:users_id, :users_id_1)")