@@ -75,6 +75,26 @@ def _transform_create(expression: exp.Expression) -> exp.Expression:
7575 return expression
7676
7777
78+ def _generated_to_auto_increment (expression : exp .Expression ) -> exp .Expression :
79+ if not isinstance (expression , exp .ColumnDef ):
80+ return expression
81+
82+ generated = expression .find (exp .GeneratedAsIdentityColumnConstraint )
83+
84+ if generated :
85+ t .cast (exp .ColumnConstraint , generated .parent ).pop ()
86+
87+ not_null = expression .find (exp .NotNullColumnConstraint )
88+ if not_null :
89+ t .cast (exp .ColumnConstraint , not_null .parent ).pop ()
90+
91+ expression .append (
92+ "constraints" , exp .ColumnConstraint (kind = exp .AutoIncrementColumnConstraint ())
93+ )
94+
95+ return expression
96+
97+
7898class SQLite (Dialect ):
7999 # https://sqlite.org/forum/forumpost/5e575586ac5c711b?raw
80100 NORMALIZATION_STRATEGY = NormalizationStrategy .CASE_INSENSITIVE
@@ -141,6 +161,7 @@ class Generator(generator.Generator):
141161 exp .CurrentDate : lambda * _ : "CURRENT_DATE" ,
142162 exp .CurrentTime : lambda * _ : "CURRENT_TIME" ,
143163 exp .CurrentTimestamp : lambda * _ : "CURRENT_TIMESTAMP" ,
164+ exp .ColumnDef : transforms .preprocess ([_generated_to_auto_increment ]),
144165 exp .DateAdd : _date_add_sql ,
145166 exp .DateStrToDate : lambda self , e : self .sql (e , "this" ),
146167 exp .If : rename_func ("IIF" ),
0 commit comments