1
Fork 0

Merge branch 'greyson-simple-sql-parser'

This commit is contained in:
Jake 2021-10-19 16:16:34 +01:00
commit f019c2d1ed
2 changed files with 15 additions and 2 deletions

View file

@ -1460,6 +1460,7 @@ TODO: change style
> statementWithoutSemicolon = choice > statementWithoutSemicolon = choice
> [keyword_ "create" *> choice [createSchema > [keyword_ "create" *> choice [createSchema
> ,createTable > ,createTable
> ,createIndex
> ,createView > ,createView
> ,createDomain > ,createDomain
> ,createSequence > ,createSequence
@ -1504,6 +1505,15 @@ TODO: change style
> <*> parens (commaSep1 (uncurry TableConstraintDef <$> tableConstraintDef > <*> parens (commaSep1 (uncurry TableConstraintDef <$> tableConstraintDef
> <|> TableColumnDef <$> columnDef)) > <|> TableColumnDef <$> columnDef))
> createIndex :: Parser Statement
> createIndex =
> CreateIndex
> <$> ((keyword_ "index" >> pure False) <|>
> (keywords_ ["unique", "index"] >> pure True))
> <*> names
> <*> (keyword_ "on" >> name)
> <*> parens (commaSep1 name)
> columnDef :: Parser ColumnDef > columnDef :: Parser ColumnDef
> columnDef = ColumnDef <$> name <*> typeName > columnDef = ColumnDef <$> name <*> typeName
> <*> optionMaybe defaultClause > <*> optionMaybe defaultClause
@ -1567,8 +1577,9 @@ TODO: change style
> colConstraintDef = > colConstraintDef =
> ColConstraintDef > ColConstraintDef
> <$> (optionMaybe (keyword_ "constraint" *> names)) > <$> (optionMaybe (keyword_ "constraint" *> names))
> <*> (notNull <|> unique <|> primaryKey <|> check <|> references) > <*> (nullable <|> notNull <|> unique <|> primaryKey <|> check <|> references)
> where > where
> 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 = ColPrimaryKeyConstraint <$ keywords_ ["primary", "key"]

View file

@ -454,6 +454,7 @@ I'm not sure if this is valid syntax or not.
> | CreateTable [Name] [TableElement] > | CreateTable [Name] [TableElement]
> | AlterTable [Name] AlterTableAction > | AlterTable [Name] AlterTableAction
> | DropTable [Name] DropBehaviour > | DropTable [Name] DropBehaviour
> | CreateIndex Bool [Name] Name [Name]
> | CreateView Bool [Name] (Maybe [Name]) > | CreateView Bool [Name] (Maybe [Name])
> QueryExpr (Maybe CheckOption) > QueryExpr (Maybe CheckOption)
> | DropView [Name] DropBehaviour > | DropView [Name] DropBehaviour
@ -572,7 +573,8 @@ I'm not sure if this is valid syntax or not.
> deriving (Eq,Show,Read,Data,Typeable) > deriving (Eq,Show,Read,Data,Typeable)
> data ColConstraint = > data ColConstraint =
> ColNotNullConstraint > ColNullableConstraint
> | ColNotNullConstraint
> | ColUniqueConstraint > | ColUniqueConstraint
> | ColPrimaryKeyConstraint > | ColPrimaryKeyConstraint
> | ColReferencesConstraint [Name] (Maybe Name) > | ColReferencesConstraint [Name] (Maybe Name)