diff --git a/beanquery/compiler.py b/beanquery/compiler.py index 9c41990..7b2de85 100644 --- a/beanquery/compiler.py +++ b/beanquery/compiler.py @@ -72,14 +72,6 @@ def __init__(self, context): self.env = Environment() self.default = context.tables.get('postings') - @property - def table(self): - return self.env.table - - @table.setter - def table(self, value): - self.env.table = value - def compile(self, query, parameters=None): """Compile an AST into an executable statement.""" self.parameters = parameters @@ -120,9 +112,9 @@ def _compile_journal(self, node: ast.Journal): @_compile_statement.register def _compile_print(self, node: ast.Print): - self.table = self.context.tables.get('entries') + self.env.table = self.context.tables.get('entries') expr = self._compile_from(node.from_clause) - return EvalPrint(self.table, expr) + return EvalPrint(self.env.table, expr) @_compile_statement.register def _compile_select(self, node: ast.Select): @@ -170,7 +162,7 @@ def _compile_select(self, node: ast.Select): 'all non-aggregates must be covered by GROUP-BY clause in aggregate query: ' 'the following targets are missing: {}'.format(','.join(missing_names))) - query = EvalQuery(self.table, + query = EvalQuery(self.env.table, c_targets, c_where, group_indexes, @@ -193,13 +185,13 @@ def _compile_from(self, node): # Subquery. if isinstance(node, ast.Select): query = self._compile_statement(node) - self.table = SubqueryTable(query) + self.env.table = SubqueryTable(query) return None # Table reference. if isinstance(node, ast.Table): - self.table = self.context.tables.get(node.name) - if self.table is None: + self.env.table = self.context.tables.get(node.name) + if self.env.table is None: raise CompilationError(f'table "{node.name}" does not exist', node) return None @@ -215,7 +207,7 @@ def _compile_from(self, node): raise CompilationError('CLOSE date must follow OPEN date') # Apply OPEN, CLOSE, and CLEAR clauses. - self.table = self.table.update(open=node.open, close=node.close, clear=node.clear) + self.env.table = self.env.table.update(open=node.open, close=node.close, clear=node.clear) return c_expression @@ -233,7 +225,7 @@ def _compile_targets(self, targets): if isinstance(targets, ast.Asterisk): # Insert the full list of available columns. targets = [ast.Target(ast.Column(name), None) - for name in self.table.wildcard_columns] + for name in self.env.table.wildcard_columns] # Compile targets. c_targets = [] @@ -496,7 +488,7 @@ def _compile(self, node: Optional[ast.Node]): @_compile.register def _column(self, node: ast.Column): - column = self.table.columns.get(node.name) + column = self.env.table.columns.get(node.name) if column is not None: return column var = self.env.get(node.name) diff --git a/beanquery/query_compile_test.py b/beanquery/query_compile_test.py index c38f4cc..192db5d 100644 --- a/beanquery/query_compile_test.py +++ b/beanquery/query_compile_test.py @@ -30,7 +30,7 @@ class TestCompileExpression(unittest.TestCase): def setUpClass(cls): context = Connection() cls.compiler = compiler.Compiler(context) - cls.compiler.table = qe.PostingsEnvironment() + cls.compiler.env.table = qe.PostingsEnvironment() def compile(self, expr): return self.compiler._compile(expr)