Compiles the nodes in a query tree to a PyMongo-compatible query dictionary.
| 63 | |
| 64 | |
| 65 | class QueryCompilerVisitor(QNodeVisitor): |
| 66 | """Compiles the nodes in a query tree to a PyMongo-compatible query |
| 67 | dictionary. |
| 68 | """ |
| 69 | |
| 70 | def __init__(self, document): |
| 71 | self.document = document |
| 72 | |
| 73 | def visit_combination(self, combination): |
| 74 | operator = "$and" |
| 75 | if combination.operation == combination.OR: |
| 76 | operator = "$or" |
| 77 | return {operator: combination.children} |
| 78 | |
| 79 | def visit_query(self, query): |
| 80 | return transform.query(self.document, **query.query) |
| 81 | |
| 82 | |
| 83 | class QNode: |