From bfa1b40b21e477b1e0f6712a2bab98983ebae85f Mon Sep 17 00:00:00 2001 From: Greyson Fischer Date: Tue, 7 Apr 2020 14:25:10 -0400 Subject: [PATCH 1/2] Added (normally defaulted) `NULL` column constraint --- Language/SQL/SimpleSQL/Parse.lhs | 3 ++- Language/SQL/SimpleSQL/Syntax.lhs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Language/SQL/SimpleSQL/Parse.lhs b/Language/SQL/SimpleSQL/Parse.lhs index ba5f684..82cd780 100644 --- a/Language/SQL/SimpleSQL/Parse.lhs +++ b/Language/SQL/SimpleSQL/Parse.lhs @@ -1564,8 +1564,9 @@ TODO: change style > colConstraintDef = > ColConstraintDef > <$> (optionMaybe (keyword_ "constraint" *> names)) -> <*> (notNull <|> unique <|> primaryKey <|> check <|> references) +> <*> (nullable <|> notNull <|> unique <|> primaryKey <|> check <|> references) > where +> nullable = ColNullableConstraint <$ keyword "null" > notNull = ColNotNullConstraint <$ keywords_ ["not", "null"] > unique = ColUniqueConstraint <$ keyword_ "unique" > primaryKey = ColPrimaryKeyConstraint <$ keywords_ ["primary", "key"] diff --git a/Language/SQL/SimpleSQL/Syntax.lhs b/Language/SQL/SimpleSQL/Syntax.lhs index 22d61c8..3dfd440 100644 --- a/Language/SQL/SimpleSQL/Syntax.lhs +++ b/Language/SQL/SimpleSQL/Syntax.lhs @@ -571,7 +571,8 @@ I'm not sure if this is valid syntax or not. > deriving (Eq,Show,Read,Data,Typeable) > data ColConstraint = -> ColNotNullConstraint +> ColNullableConstraint +> | ColNotNullConstraint > | ColUniqueConstraint > | ColPrimaryKeyConstraint > | ColReferencesConstraint [Name] (Maybe Name) From 54cefdc2ee89a4319d6b9e7cb78e57992a916fc5 Mon Sep 17 00:00:00 2001 From: Greyson Fischer Date: Wed, 8 Apr 2020 01:05:07 -0400 Subject: [PATCH 2/2] Added basic `CREATE INDEX` parsing --- Language/SQL/SimpleSQL/Parse.lhs | 10 ++++++++++ Language/SQL/SimpleSQL/Syntax.lhs | 1 + 2 files changed, 11 insertions(+) diff --git a/Language/SQL/SimpleSQL/Parse.lhs b/Language/SQL/SimpleSQL/Parse.lhs index 82cd780..cb8c5df 100644 --- a/Language/SQL/SimpleSQL/Parse.lhs +++ b/Language/SQL/SimpleSQL/Parse.lhs @@ -1460,6 +1460,7 @@ TODO: change style > statement = choice > [keyword_ "create" *> choice [createSchema > ,createTable +> ,createIndex > ,createView > ,createDomain > ,createSequence @@ -1501,6 +1502,15 @@ TODO: change style > <*> parens (commaSep1 (uncurry TableConstraintDef <$> tableConstraintDef > <|> 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 = ColumnDef <$> name <*> typeName > <*> optionMaybe defaultClause diff --git a/Language/SQL/SimpleSQL/Syntax.lhs b/Language/SQL/SimpleSQL/Syntax.lhs index 3dfd440..886734c 100644 --- a/Language/SQL/SimpleSQL/Syntax.lhs +++ b/Language/SQL/SimpleSQL/Syntax.lhs @@ -454,6 +454,7 @@ I'm not sure if this is valid syntax or not. > | CreateTable [Name] [TableElement] > | AlterTable [Name] AlterTableAction > | DropTable [Name] DropBehaviour +> | CreateIndex Bool [Name] Name [Name] > | CreateView Bool [Name] (Maybe [Name]) > QueryExpr (Maybe CheckOption) > | DropView [Name] DropBehaviour