Skip to content

Commit

Permalink
Refactor mermaid rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharad committed Nov 14, 2024
1 parent 2c104b5 commit 46c1cf2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Binary file modified sql2er-wasm.wasm
Binary file not shown.
12 changes: 6 additions & 6 deletions src/Sql2er/Mermaid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Sql2er.Mermaid where
import Data.Text (Text)
import Data.Text qualified as T
import Sql2er.Common.Types
import Data.Maybe (fromMaybe)
import Data.Maybe (fromMaybe, mapMaybe)

-- Function to convert SqlType to a simplified string representation for Mermaid
sqlTypeToString :: SqlType -> Text
Expand Down Expand Up @@ -61,13 +61,13 @@ tableToMermaid Table {tableName, columns} =
<> addForeignKeys tableName columns

addForeignKeys :: TableName -> [Column] -> Text
addForeignKeys originTableName cols = mconcat $ map addForeignKeys_ cols
addForeignKeys originTableName cols = T.unlines $ map addForeignKeys_ cols
where
addForeignKeys_ Column{cConstraints} = mconcat $ map referenceColumnToText cConstraints
referenceColumnToText :: ColumnConstraint -> Text
addForeignKeys_ Column{cConstraints} = T.unlines $ mapMaybe referenceColumnToText cConstraints
referenceColumnToText :: ColumnConstraint -> Maybe Text
referenceColumnToText (ReferencesColumn tName mColName) = do
originTableName <> " ||--o{ " <> tName <> " : " <> fromMaybe "relation" mColName
referenceColumnToText _ = ""
Just $ originTableName <> " ||--o{ " <> tName <> " : " <> fromMaybe "relation" mColName
referenceColumnToText _ = Nothing

-- Function to create relationship representation for ForeignKeyConstraint
foreignKeyToMermaid :: TableName -> TableConstraint -> [Text]
Expand Down

0 comments on commit 46c1cf2

Please sign in to comment.