Commits

timostolz committed ddc26c6 Merge

merged change

Comments (0)

Files changed (1)

 #!/usr/bin/env python
+import decimal
 
 cdef class Query:
     cdef list conditions
     cdef public int max_rows
     cdef constchar_p order_column
     
-    def __init__(Query self, *conditions):
+    def __init__(Query self, *conditions, **kwargs):
         self.conditions = [c for c in conditions if isinstance(c, Condition)]
-        self.offset = 0
-        self.max_rows = -1
+        self.offset = kwargs.pop("offset", 0)
+        self.max_rows = kwargs.pop("max_rows", -1)
         self.order_column = NULL
+        
+        for k, v in kwargs.items():
+            if isinstance(v, unicode):
+                v = v.encode('utf8')
+            if isinstance(v, str):
+                self.conditions.append(Condition(k, EQUALS, v))
+            elif isinstance(v, (int, long, float, decimal.Decimal)):
+                self.conditions.append(Condition(k, NUM_EQUALS, str(v)))
+            else:
+                raise ValueError("%r => %r, unicode, str, int, long, float or Decimal expected.")
 
     def __and__(Query self, other):
         if isinstance(other, Condition) and other not in self.conditions:
                 self.order_mode = NUM_ASC
             else:
                 self.order_mode = STRING_ASC
+        return self
 
 cdef class Condition:
     cdef str col
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.