### Mermerd Example Usages Source: https://github.com/karnerth/mermerd/blob/master/readme.md Demonstrates various ways to invoke Mermerd, from interactive CLI usage to specifying configurations via flags and run files. ```bash # all parameters are provided via the interactive cli mermerd ``` ```bash # same as previous one, but show all constraints even though the table of the resulting constraint was not selected mermerd --showAllConstraints ``` ```bash # ERD is created via the provided run config mermerd --runConfig yourRunConfig.yaml ``` ```bash # specify all connection properties so that only the table selection is done via the interactive cli mermerd -c "postgresql://user:password@localhost:5432/yourDb" -s public ``` ```bash # same as previous one, but use all available tables without interaction mermerd -c "postgresql://user:password@localhost:5432/yourDb" -s public --useAllTables ``` ```bash # same as previous one, but get the result in stdout instead of a file mermerd -c "postgresql://user:password@localhost:5432/yourDb" -s public --useAllTables --outputMode stdout ``` ```bash # same as previous one, but use a list of tables without interaction mermerd -c "postgresql://user:password@localhost:5432/yourDb" -s public --selectedTables article,article_label ``` -------------------------------- ### Install Mermerd using Go Toolchain Source: https://context7.com/karnerth/mermerd/llms.txt Install the latest or a specific version of Mermerd using the Go toolchain. Verify the installation by checking the version. ```sh go install github.com/KarnerTh/mermerd@latest ``` ```sh go install github.com/KarnerTh/mermerd@v0.13.0 ``` ```sh mermerd version # Output: mermerd v0.13.0 ``` -------------------------------- ### Mermerd Global Configuration File Example Source: https://github.com/karnerth/mermerd/blob/master/readme.md Configure default Mermerd settings using a `.mermerd` YAML file in your home directory. This file can set persistent options and provide connection string suggestions. ```yaml showAllConstraints: true encloseWithMermaidBackticks: true outputFileName: "my-db.mmd" debug: false omitConstraintLabels: false omitAttributeKeys: false showDescriptions: "enumValues" showSchemaPrefix: true schemaPrefixSeparator: "_" # These connection strings are available as suggestions in the cli (use tab to access) connectionStringSuggestions: - postgresql://user:password@localhost:5432/yourDb - mysql://root:password@tcp(127.0.0.1:3306)/yourDb - sqlserver://user:password@localhost:1433?database=yourDb - sqlite3://mermerd_test.db ``` -------------------------------- ### Install Mermerd using Go Toolchain Source: https://github.com/karnerth/mermerd/blob/master/readme.md Install the latest or a specific version of Mermerd using the go install command. Requires go version >= 1.21. ```sh go install github.com/KarnerTh/mermerd@latest ``` ```sh go install github.com/KarnerTh/mermerd@v0.12.0 ``` -------------------------------- ### Mermerd Run Configuration File Example Source: https://github.com/karnerth/mermerd/blob/master/readme.md Define all necessary parameters for generating an ERD in a YAML file, which can then be used with the `--runConfig` flag. This is useful for CI/CD pipelines. ```yaml # Connection properties connectionString: "postgresql://user:password@localhost:5432/yourDb" # Define what schemas should be used useAllSchemas: true # or schema: - "public" - "other_db" # Define what tables should be used useAllTables: true # or selectedTables: - city - customer # Additional flags showAllConstraints: true encloseWithMermaidBackticks: true outputFileName: "my-db.mmd" outputMode: stdout debug: true omitConstraintLabels: true omitAttributeKeys: true showDescriptions: - enumValues - columnComments - notNull showSchemaPrefix: true schemaPrefixSeparator: "_" ignoreTables: - city # Names must match the pattern relationshipLabels: - "public_table public_another-table : label" ``` -------------------------------- ### Example Mermaid ER Diagram Output Source: https://context7.com/karnerth/mermerd/llms.txt A complete ER diagram generated by Mermerd, showcasing schema prefixes, description options, and relationship symbols. ```mermaid erDiagram public_article { int4 id PK "{NOT_NULL}" varchar status FK " {NOT_NULL}" varchar title "{NOT_NULL}" int4 author_id FK } public_author { int4 id PK "{NOT_NULL}" varchar name "{NOT_NULL}" } public_article }o--|| public_author : "author_id" ``` -------------------------------- ### Run Unit Tests Source: https://github.com/karnerth/mermerd/blob/master/readme.md Execute unit tests using the `go test` command with the `--short` flag. This command runs all unit tests and provides verbose output. ```bash go test --short -v ./... ``` -------------------------------- ### Run All Tests Source: https://github.com/karnerth/mermerd/blob/master/readme.md Execute all unit and integration tests using the `go test` command. This command runs all tests and provides verbose output. ```bash go test -v ./... ``` -------------------------------- ### Run Unit Tests with Makefile Source: https://github.com/karnerth/mermerd/blob/master/readme.md Use the `make test-unit` target to run all unit tests. ```bash make test-unit ``` -------------------------------- ### Run All Tests with Makefile Source: https://github.com/karnerth/mermerd/blob/master/readme.md Use the `make test-all` target to run all unit and integration tests. ```bash make test-all ``` -------------------------------- ### Run Mermerd in Interactive CLI Mode Source: https://context7.com/karnerth/mermerd/llms.txt Launch Mermerd interactively to be prompted for connection string, schema, and table selection. Use `--showAllConstraints` to include constraints for tables not explicitly selected. ```sh # Fully interactive: prompts for connection string, schema, and tables mermerd ``` ```sh # Show all constraints even for tables not in the selection mermerd --showAllConstraints ``` -------------------------------- ### Create Database Connector with Factory Source: https://context7.com/karnerth/mermerd/llms.txt Use the ConnectorFactory to create a database connector based on the connection string prefix. Supported prefixes include postgresql, mysql, sqlserver, and sqlite3. Ensure proper error handling for unrecognized prefixes. ```go package main import ( "fmt" "github.com/KarnerTh/mermerd/database" ) func main() { factory := database.NewConnectorFactory() // Create a PostgreSQL connector connector, err := factory.NewConnector("postgresql://user:password@localhost:5432/mydb") if err != nil { panic(err) // "could not create connector for db" if prefix is unrecognized } // Connect to the database if err := connector.Connect(); err != nil { panic(err) } defer connector.Close() // Retrieve available schemas schemas, err := connector.GetSchemas() if err != nil { panic(err) } fmt.Println("Schemas:", schemas) // e.g. [public audit] // Retrieve tables for a schema tables, err := connector.GetTables([]string{"public"}) if err != nil { panic(err) } // tables: []TableDetail{{Schema:"public", Name:"article"}, {Schema:"public", Name:"author"}, ...} // Retrieve columns for a specific table columns, err := connector.GetColumns(database.TableDetail{Schema: "public", Name: "article"}) if err != nil { panic(err) } for _, col := range columns { fmt.Printf(" %s %s PK=%v FK=%v Unique=%v Nullable=%v\n", col.DataType, col.Name, col.IsPrimary, col.IsForeign, col.IsUnique, col.IsNullable) } // Retrieve FK/PK constraints for a table constraints, err := connector.GetConstraints(database.TableDetail{Schema: "public", Name: "article"}) if err != nil { panic(err) } for _, c := range constraints { fmt.Printf(" FK %s.%s → PK %s.%s (col: %s)\n", c.FkSchema, c.FkTable, c.PkSchema, c.PkTable, c.ColumnName) } } ``` -------------------------------- ### Control Output Destination and Format Source: https://context7.com/karnerth/mermerd/llms.txt Configure the output using `--outputMode` and `-o` / `--outputFileName`. Default is `result.mmd`. Use `stdout` for piping and `-e` to enclose output in Mermaid fences for Markdown embedding. ```sh # Write to a specific file mermerd -c "postgresql://user:password@localhost:5432/yourDb" -s public \ --useAllTables -o schema-diagram.mmd ``` ```sh # Stream to stdout (e.g. for piping into another tool) mermerd -c "postgresql://user:password@localhost:5432/yourDb" -s public \ --useAllTables --outputMode stdout ``` ```sh # Enclose output in mermaid backtick fences for GitHub Markdown embedding mermerd -c "postgresql://user:password@localhost:5432/yourDb" -s public \ --useAllTables --outputMode stdout -e # Output: # ```mermaid # erDiagram # article { ... } # ``` ``` -------------------------------- ### Run Mermerd with a Configuration File Source: https://context7.com/karnerth/mermerd/llms.txt Use `--runConfig` to specify a YAML file containing all Mermerd flags for non-interactive diagram generation, suitable for CI/CD. ```yaml # ci-erd.yaml — full run configuration example # Database connection connectionString: "postgresql://user:password@localhost:5432/yourDb" # Schema selection (pick one approach) useAllSchemas: false schema: - "public" - "audit" # Table selection (pick one approach) useAllTables: false selectedTables: - public.article - public.author - public.label - audit.change_log # Tables to ignore (supports regex patterns) ignoreTables: - schema_migrations - "temp_.*" # Output settings outputFileName: "docs/schema.mmd" outputMode: file # or: stdout encloseWithMermaidBackticks: true # Diagram display options showAllConstraints: true omitConstraintLabels: false omitAttributeKeys: false showDescriptions: - enumValues - columnComments - notNull showSchemaPrefix: true schemaPrefixSeparator: "_" # Custom relationship labels (format: " :