Merge pull request #50 from Airsequel/autoincrement
Support autoincrement columns
This commit is contained in:
commit
d8b32c0931
|
@ -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
|
||||||
|
|
|
@ -1587,13 +1587,19 @@ TODO: change style
|
||||||
> colConstraintDef :: Parser ColConstraintDef
|
> colConstraintDef :: Parser ColConstraintDef
|
||||||
> colConstraintDef =
|
> colConstraintDef =
|
||||||
> ColConstraintDef
|
> ColConstraintDef
|
||||||
> <$> (optionMaybe (keyword_ "constraint" *> names))
|
> <$> optionMaybe (keyword_ "constraint" *> names)
|
||||||
> <*> (nullable <|> notNull <|> unique <|> primaryKey <|> check <|> references)
|
> <*> (nullable <|> notNull <|> unique <|> primaryKey <|> check <|> references)
|
||||||
> where
|
> where
|
||||||
> nullable = ColNullableConstraint <$ keyword "null"
|
> nullable = ColNullableConstraint <$ keyword "null"
|
||||||
> notNull = ColNotNullConstraint <$ keywords_ ["not", "null"]
|
> notNull = ColNotNullConstraint <$ keywords_ ["not", "null"]
|
||||||
> unique = ColUniqueConstraint <$ keyword_ "unique"
|
> unique = ColUniqueConstraint <$ keyword_ "unique"
|
||||||
> primaryKey = ColPrimaryKeyConstraint <$ keywords_ ["primary", "key"]
|
> primaryKey = do
|
||||||
|
> keywords_ ["primary", "key"]
|
||||||
|
> d <- getState
|
||||||
|
> autoincrement <- if diAutoincrement d
|
||||||
|
> then optionMaybe (keyword_ "autoincrement")
|
||||||
|
> else pure Nothing
|
||||||
|
> pure $ ColPrimaryKeyConstraint $ isJust autoincrement
|
||||||
> check = keyword_ "check" >> ColCheckConstraint <$> parens scalarExpr
|
> check = keyword_ "check" >> ColCheckConstraint <$> parens scalarExpr
|
||||||
> references = keyword_ "references" >>
|
> references = keyword_ "references" >>
|
||||||
> (\t c m (ou,od) -> ColReferencesConstraint t c m ou od)
|
> (\t c m (ou,od) -> ColReferencesConstraint t c m ou od)
|
||||||
|
|
|
@ -702,7 +702,8 @@ Try to do this when this code is ported to a modern pretty printing lib.
|
||||||
> <+> pcon con
|
> <+> pcon con
|
||||||
> pcon ColNotNullConstraint = texts ["not","null"]
|
> pcon ColNotNullConstraint = texts ["not","null"]
|
||||||
> pcon ColUniqueConstraint = text "unique"
|
> pcon ColUniqueConstraint = text "unique"
|
||||||
> pcon ColPrimaryKeyConstraint = texts ["primary","key"]
|
> pcon (ColPrimaryKeyConstraint autoincrement) =
|
||||||
|
> texts $ ["primary","key"] ++ ["autoincrement"|autoincrement]
|
||||||
> pcon (ColCheckConstraint v) = text "check" <+> parens (scalarExpr d v)
|
> pcon (ColCheckConstraint v) = text "check" <+> parens (scalarExpr d v)
|
||||||
> pcon (ColReferencesConstraint tb c m u del) =
|
> pcon (ColReferencesConstraint tb c m u del) =
|
||||||
> text "references"
|
> text "references"
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
> ,IdentityWhen(..)
|
> ,IdentityWhen(..)
|
||||||
> ,SequenceGeneratorOption(..)
|
> ,SequenceGeneratorOption(..)
|
||||||
> ,ColConstraintDef(..)
|
> ,ColConstraintDef(..)
|
||||||
|
> ,AutoincrementClause
|
||||||
> ,ColConstraint(..)
|
> ,ColConstraint(..)
|
||||||
> ,TableConstraint(..)
|
> ,TableConstraint(..)
|
||||||
> ,ReferenceMatch(..)
|
> ,ReferenceMatch(..)
|
||||||
|
@ -575,11 +576,13 @@ I'm not sure if this is valid syntax or not.
|
||||||
> -- (Maybe [ConstraintCharacteristics])
|
> -- (Maybe [ConstraintCharacteristics])
|
||||||
> deriving (Eq,Show,Read,Data,Typeable)
|
> deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
|
> type AutoincrementClause = Bool
|
||||||
|
>
|
||||||
> data ColConstraint =
|
> data ColConstraint =
|
||||||
> ColNullableConstraint
|
> ColNullableConstraint
|
||||||
> | ColNotNullConstraint
|
> | ColNotNullConstraint
|
||||||
> | ColUniqueConstraint
|
> | ColUniqueConstraint
|
||||||
> | ColPrimaryKeyConstraint
|
> | ColPrimaryKeyConstraint AutoincrementClause
|
||||||
> | ColReferencesConstraint [Name] (Maybe Name)
|
> | ColReferencesConstraint [Name] (Maybe Name)
|
||||||
> ReferenceMatch
|
> ReferenceMatch
|
||||||
> ReferentialAction
|
> ReferentialAction
|
||||||
|
@ -730,6 +733,6 @@ I'm not sure if this is valid syntax or not.
|
||||||
|
|
||||||
> -- | Comment. Useful when generating SQL code programmatically. The
|
> -- | Comment. Useful when generating SQL code programmatically. The
|
||||||
> -- parser doesn't produce these.
|
> -- parser doesn't produce these.
|
||||||
> data Comment = BlockComment String
|
> newtype Comment = BlockComment String
|
||||||
> deriving (Eq,Show,Read,Data,Typeable)
|
> deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
|
|
|
@ -332,7 +332,13 @@ todo: constraint characteristics
|
||||||
> "create table t (a int primary key);"
|
> "create table t (a int primary key);"
|
||||||
> $ 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
|
||||||
> [ColConstraintDef Nothing ColPrimaryKeyConstraint]])
|
> [ColConstraintDef Nothing (ColPrimaryKeyConstraint False)]])
|
||||||
|
|
||||||
|
> ,(TestStatement ansi2011 { diAutoincrement = True }
|
||||||
|
> "create table t (a int primary key autoincrement);"
|
||||||
|
> $ CreateTable [Name Nothing "t"]
|
||||||
|
> [TableColumnDef $ ColumnDef (Name Nothing "a") (TypeName [Name Nothing "int"]) Nothing
|
||||||
|
> [ColConstraintDef Nothing (ColPrimaryKeyConstraint True)]])
|
||||||
|
|
||||||
references t(a,b)
|
references t(a,b)
|
||||||
[ Full |partial| simepl]
|
[ Full |partial| simepl]
|
||||||
|
|
Loading…
Reference in a new issue