1
Fork 0

Add autoincrement option to dialect

This commit is contained in:
Matei Adriel 2024-01-08 22:10:14 +01:00
parent c997e3196c
commit d53afd905e
No known key found for this signature in database
3 changed files with 8 additions and 2 deletions

View file

@ -90,6 +90,8 @@ Data types to represent different dialect options
> ,diSqlServerSymbols :: Bool > ,diSqlServerSymbols :: Bool
> -- | allow sql server style for CONVERT function in format CONVERT(data_type(length), expression, style) > -- | allow sql server style for CONVERT function in format CONVERT(data_type(length), expression, style)
> ,diConvertFunction :: Bool > ,diConvertFunction :: Bool
> -- | allow creating autoincrement columns
> ,diAutoincrement :: Bool
> } > }
> deriving (Eq,Show,Read,Data,Typeable) > deriving (Eq,Show,Read,Data,Typeable)
@ -112,6 +114,7 @@ Data types to represent different dialect options
> ,diPostgresSymbols = False > ,diPostgresSymbols = False
> ,diSqlServerSymbols = False > ,diSqlServerSymbols = False
> ,diConvertFunction = False > ,diConvertFunction = False
> ,diAutoincrement = False
> } > }
> -- | mysql dialect > -- | mysql dialect

View file

@ -1595,7 +1595,10 @@ TODO: change style
> unique = ColUniqueConstraint <$ keyword_ "unique" > unique = ColUniqueConstraint <$ keyword_ "unique"
> primaryKey = do > primaryKey = do
> keywords_ ["primary", "key"] > keywords_ ["primary", "key"]
> autoincrement <- optionMaybe (keyword_ "autoincrement") > d <- getState
> autoincrement <- if diAutoincrement d
> then optionMaybe (keyword_ "autoincrement")
> else pure Nothing
> pure $ ColPrimaryKeyConstraint $ isJust autoincrement > pure $ ColPrimaryKeyConstraint $ isJust autoincrement
> check = keyword_ "check" >> ColCheckConstraint <$> parens scalarExpr > check = keyword_ "check" >> ColCheckConstraint <$> parens scalarExpr
> references = keyword_ "references" >> > references = keyword_ "references" >>

View file

@ -334,7 +334,7 @@ todo: constraint characteristics
> [TableColumnDef $ ColumnDef (Name Nothing "a") (TypeName [Name Nothing "int"]) Nothing > [TableColumnDef $ ColumnDef (Name Nothing "a") (TypeName [Name Nothing "int"]) Nothing
> [ColConstraintDef Nothing (ColPrimaryKeyConstraint False)]]) > [ColConstraintDef Nothing (ColPrimaryKeyConstraint False)]])
> ,(TestStatement ansi2011 > ,(TestStatement ansi2011 { diAutoincrement = True }
> "create table t (a int primary key autoincrement);" > "create table t (a int primary key autoincrement);"
> $ CreateTable [Name Nothing "t"] > $ CreateTable [Name Nothing "t"]
> [TableColumnDef $ ColumnDef (Name Nothing "a") (TypeName [Name Nothing "int"]) Nothing > [TableColumnDef $ ColumnDef (Name Nothing "a") (TypeName [Name Nothing "int"]) Nothing