2525 Computed ,
2626 Constraint ,
2727 DefaultClause ,
28+ Dialect ,
2829 Enum ,
2930 Float ,
3031 ForeignKey ,
3940 UniqueConstraint ,
4041)
4142from sqlalchemy .dialects .postgresql import JSONB
42- from sqlalchemy .engine import Connection , Engine
4343from sqlalchemy .exc import CompileError
4444from sqlalchemy .sql .elements import TextClause
4545
@@ -95,10 +95,10 @@ class CodeGenerator(metaclass=ABCMeta):
9595 valid_options : ClassVar [set [str ]] = set ()
9696
9797 def __init__ (
98- self , metadata : MetaData , bind : Connection | Engine , options : Sequence [str ]
98+ self , metadata : MetaData , dialect : Dialect , options : Sequence [str ]
9999 ):
100100 self .metadata : MetaData = metadata
101- self .bind : Connection | Engine = bind
101+ self .dialect : Dialect = dialect
102102 self .options : set [str ] = set (options )
103103
104104 # Validate options
@@ -124,12 +124,12 @@ class TablesGenerator(CodeGenerator):
124124 def __init__ (
125125 self ,
126126 metadata : MetaData ,
127- bind : Connection | Engine ,
127+ dialect : Dialect ,
128128 options : Sequence [str ],
129129 * ,
130130 indentation : str = " " ,
131131 ):
132- super ().__init__ (metadata , bind , options )
132+ super ().__init__ (metadata , dialect , options )
133133 self .indentation : str = indentation
134134 self .imports : dict [str , set [str ]] = defaultdict (set )
135135 self .module_imports : set [str ] = set ()
@@ -562,7 +562,7 @@ def add_fk_options(*opts: Any) -> None:
562562 ]
563563 add_fk_options (local_columns , remote_columns )
564564 elif isinstance (constraint , CheckConstraint ):
565- args .append (repr (get_compiled_expression (constraint .sqltext , self .bind )))
565+ args .append (repr (get_compiled_expression (constraint .sqltext , self .dialect )))
566566 elif isinstance (constraint , (UniqueConstraint , PrimaryKeyConstraint )):
567567 args .extend (repr (col .name ) for col in constraint .columns )
568568 else :
@@ -608,7 +608,7 @@ def fix_column_types(self, table: Table) -> None:
608608 # Detect check constraints for boolean and enum columns
609609 for constraint in table .constraints .copy ():
610610 if isinstance (constraint , CheckConstraint ):
611- sqltext = get_compiled_expression (constraint .sqltext , self .bind )
611+ sqltext = get_compiled_expression (constraint .sqltext , self .dialect )
612612
613613 # Turn any integer-like column with a CheckConstraint like
614614 # "column IN (0, 1)" into a Boolean
@@ -646,7 +646,7 @@ def fix_column_types(self, table: Table) -> None:
646646 pass
647647
648648 # PostgreSQL specific fix: detect sequences from server_default
649- if column .server_default and self .bind . dialect .name == "postgresql" :
649+ if column .server_default and self .dialect .name == "postgresql" :
650650 if isinstance (column .server_default , DefaultClause ) and isinstance (
651651 column .server_default .arg , TextClause
652652 ):
@@ -661,7 +661,7 @@ def fix_column_types(self, table: Table) -> None:
661661 column .server_default = None
662662
663663 def get_adapted_type (self , coltype : Any ) -> Any :
664- compiled_type = coltype .compile (self .bind . engine . dialect )
664+ compiled_type = coltype .compile (self .dialect )
665665 for supercls in coltype .__class__ .__mro__ :
666666 if not supercls .__name__ .startswith ("_" ) and hasattr (
667667 supercls , "__visit_name__"
@@ -687,7 +687,7 @@ def get_adapted_type(self, coltype: Any) -> Any:
687687 try :
688688 # If the adapted column type does not render the same as the
689689 # original, don't substitute it
690- if new_coltype .compile (self .bind . engine . dialect ) != compiled_type :
690+ if new_coltype .compile (self .dialect ) != compiled_type :
691691 # Make an exception to the rule for Float and arrays of Float,
692692 # since at least on PostgreSQL, Float can accurately represent
693693 # both REAL and DOUBLE_PRECISION
@@ -718,13 +718,13 @@ class DeclarativeGenerator(TablesGenerator):
718718 def __init__ (
719719 self ,
720720 metadata : MetaData ,
721- bind : Connection | Engine ,
721+ dialect : Dialect ,
722722 options : Sequence [str ],
723723 * ,
724724 indentation : str = " " ,
725725 base_class_name : str = "Base" ,
726726 ):
727- super ().__init__ (metadata , bind , options , indentation = indentation )
727+ super ().__init__ (metadata , dialect , options , indentation = indentation )
728728 self .base_class_name : str = base_class_name
729729 self .inflect_engine = inflect .engine ()
730730
@@ -1305,7 +1305,7 @@ class DataclassGenerator(DeclarativeGenerator):
13051305 def __init__ (
13061306 self ,
13071307 metadata : MetaData ,
1308- bind : Connection | Engine ,
1308+ dialect : Dialect ,
13091309 options : Sequence [str ],
13101310 * ,
13111311 indentation : str = " " ,
@@ -1315,7 +1315,7 @@ def __init__(
13151315 ):
13161316 super ().__init__ (
13171317 metadata ,
1318- bind ,
1318+ dialect ,
13191319 options ,
13201320 indentation = indentation ,
13211321 base_class_name = base_class_name ,
@@ -1344,15 +1344,15 @@ class SQLModelGenerator(DeclarativeGenerator):
13441344 def __init__ (
13451345 self ,
13461346 metadata : MetaData ,
1347- bind : Connection | Engine ,
1347+ dialect : Dialect ,
13481348 options : Sequence [str ],
13491349 * ,
13501350 indentation : str = " " ,
13511351 base_class_name : str = "SQLModel" ,
13521352 ):
13531353 super ().__init__ (
13541354 metadata ,
1355- bind ,
1355+ dialect ,
13561356 options ,
13571357 indentation = indentation ,
13581358 base_class_name = base_class_name ,
0 commit comments