Skip to content

Commit

Permalink
Add Ord instance on schema, enables sorted table names in IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Hamilton committed Dec 7, 2020
1 parent 3ab74b6 commit 1dcc70d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions IHP/IDE/SchemaDesigner/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ parseSchemaSql = do
let result = runParser parseDDL (cs schemaFilePath) schemaSql
case result of
Left error -> pure (Left (cs $ errorBundlePretty error))
Right r -> pure (Right r)
Right r -> pure (Right (sort r))

type Parser = Parsec Void Text

Expand Down Expand Up @@ -330,8 +330,8 @@ sqlType = choice $ map optionalArray

expression :: Parser Expression
expression = do
e <- try callExpr <|> varExpr <|> textExpr
space
e <- try callExpr <|> varExpr <|> textExpr
space
pure e

varExpr :: Parser Expression
Expand Down
16 changes: 8 additions & 8 deletions IHP/IDE/SchemaDesigner/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data Statement
| AddConstraint { tableName :: Text, constraintName :: Text, constraint :: Constraint }
| UnknownStatement { raw :: Text }
| Comment { content :: Text }
deriving (Eq, Show)
deriving (Eq, Show, Ord)

data CreateTable
= CreateTable
Expand All @@ -28,7 +28,7 @@ data CreateTable
, primaryKeyConstraint :: PrimaryKeyConstraint
, constraints :: [Constraint]
}
deriving (Eq, Show)
deriving (Eq, Show, Ord)

data Column = Column
{ name :: Text
Expand All @@ -37,19 +37,19 @@ data Column = Column
, notNull :: Bool
, isUnique :: Bool
}
deriving (Eq, Show)
deriving (Eq, Show, Ord)

data OnDelete
= NoAction
| Restrict
| SetNull
| SetDefault
| Cascade
deriving (Show, Eq)
deriving (Show, Eq, Ord)

newtype PrimaryKeyConstraint
= PrimaryKeyConstraint { primaryKeyColumnNames :: [Text] }
deriving (Eq, Show)
deriving (Eq, Show, Ord)

data Constraint
-- | FOREIGN KEY (columnName) REFERENCES referenceTable (referenceColumn) ON DELETE onDelete;
Expand All @@ -61,7 +61,7 @@ data Constraint
}
| UniqueConstraint
{ columnNames :: [Text] }
deriving (Eq, Show)
deriving (Eq, Show, Ord)

data Expression =
-- | Sql string like @'hello'@
Expand All @@ -70,7 +70,7 @@ data Expression =
| VarExpression Text
-- | Simple call, like @COALESCE(name, 'unknown name')@
| CallExpression Text [Expression]
deriving (Eq, Show)
deriving (Eq, Show, Ord)

data PostgresType
= PUUID
Expand All @@ -94,4 +94,4 @@ data PostgresType
| PJSONB
| PArray PostgresType
| PCustomType Text
deriving (Eq, Show)
deriving (Eq, Show, Ord)

0 comments on commit 1dcc70d

Please sign in to comment.