@@ -90,17 +90,11 @@ class CompileError(Exception):
90
90
pass
91
91
92
92
93
- # TODO: LATER: Resolve the circular imports of databases-compiler-dialects:
94
- # A database uses a compiler to render the SQL query.
95
- # The compiler delegates to a dialect.
96
- # The dialect renders the SQL.
97
- # AS IS: The dialect requires the db to normalize table paths — leading to the back-dependency.
98
- # TO BE: All the tables paths must be pre-normalized before SQL rendering.
99
- # Also: c.database.is_autocommit in render_commit().
100
- # After this, the Compiler can cease referring Database/Dialect at all,
101
- # and be used only as a CompilingContext (a counter/data-bearing class).
102
- # As a result, it becomes low-level util, and the circular dependency auto-resolves.
103
- # Meanwhile, the easy fix is to simply move the Compiler here.
93
+ # TODO: remove once switched to attrs, where ForwardRef[]/strings are resolved.
94
+ class _RuntypeHackToFixCicularRefrencedDatabase :
95
+ dialect : "BaseDialect"
96
+
97
+
104
98
@dataclass
105
99
class Compiler (AbstractCompiler ):
106
100
"""
@@ -113,7 +107,7 @@ class Compiler(AbstractCompiler):
113
107
# Database is needed to normalize tables. Dialect is needed for recursive compilations.
114
108
# In theory, it is many-to-many relations: e.g. a generic ODBC driver with multiple dialects.
115
109
# In practice, we currently bind the dialects to the specific database classes.
116
- database : "Database"
110
+ database : _RuntypeHackToFixCicularRefrencedDatabase
117
111
118
112
in_select : bool = False # Compilation runtime flag
119
113
in_join : bool = False # Compilation runtime flag
@@ -125,7 +119,7 @@ class Compiler(AbstractCompiler):
125
119
_counter : List = field (default_factory = lambda : [0 ])
126
120
127
121
@property
128
- def dialect (self ) -> "Dialect " :
122
+ def dialect (self ) -> "BaseDialect " :
129
123
return self .database .dialect
130
124
131
125
# TODO: DEPRECATED: Remove once the dialect is used directly in all places.
@@ -844,7 +838,7 @@ def __getitem__(self, i):
844
838
return self .rows [i ]
845
839
846
840
847
- class Database (abc .ABC ):
841
+ class Database (abc .ABC , _RuntypeHackToFixCicularRefrencedDatabase ):
848
842
"""Base abstract class for databases.
849
843
850
844
Used for providing connection code and implementation specific SQL utilities.
0 commit comments