Commit 2f95668e authored by Philipp Middendorf's avatar Philipp Middendorf
Browse files

Show nullability in diagram as well

parent 44bbd340
Pipeline #4128 passed with stage
in 2 minutes and 47 seconds
......@@ -139,7 +139,7 @@ parserNormalField = do
fieldName <- lexeme parserIdentifier <?> "column identifier"
fieldType <- lexeme parserType <?> "column type"
optional (symbol "DEFAULT (CURRENT_TIMESTAMP)")
nullability <- optional (symbol "NOT" *> symbol "NULL" $> True) <?> "column nullability"
nullability <- optional (symbol "NOT" *> symbol "NULL" $> False) <?> "column nullability"
pure (NormalField fieldName fieldType (fromMaybe True nullability))
parserField :: Text -> Parser SqlField
......@@ -150,11 +150,11 @@ parserField tableName = parserPrimaryKey
<|> parserNormalField
serializeField :: SqlField -> Text
serializeField (NormalField name type_ nullability) = "<tr><td port=\"" <> name <> "\">" <> name <> "</td><td port=\"" <> name <> "_right\">" <> pack (show type_) <> "</td></tr>"
serializeField (NormalField name type_ nullability) = "<tr><td port=\"" <> name <> "\">" <> name <> "</td><td>" <> pack (show type_) <> "</td><td port=\"" <> name <> "_right\">" <> (if nullability then "NULL" else "") <> "</td></tr>"
serializeField _ = ""
serializeCreateTable :: SqlCreateTable -> Text
serializeCreateTable ct = "\"" <> ctName ct <> "\" [\nshape=none\nlabel=<\n <table border=\"0\" cellspacing=\"0\" cellborder=\"1\">\n <tr><td bgcolor=\"lightblue2\" colspan=\"2\"><font point-size=\"20\"> " <> ctName ct <> " </font></td></tr>\n " <> foldMap serializeField (ctFields ct) <> "\n</table>\n>];\n"
serializeCreateTable ct = "\"" <> ctName ct <> "\" [\nshape=none\nlabel=<\n <table border=\"0\" cellspacing=\"0\" cellborder=\"1\">\n <tr><td bgcolor=\"lightblue2\" colspan=\"3\"><font point-size=\"20\"> " <> ctName ct <> " </font></td></tr>\n " <> foldMap serializeField (ctFields ct) <> "\n</table>\n>];\n"
serializeForeignKey :: SqlForeignKey -> Text
serializeForeignKey (SqlForeignKey tableLeft leftColumn tableRight rightColumn) = "\"" <> tableLeft <> "\":" <> leftColumn <> "_right -> \"" <> tableRight <> "\":" <> rightColumn
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment