- a command line tool for generating create sql from mermaid erDiagram
npm install -g @funktechno/little-mermaid-2-the-sql
littleMermaid2SQL --help
littleMermaid2SQL -d dbType --src markdownFilePath
- see samples for more information
npm install --save @funktechno/little-mermaid-2-the-sql
- Example
-
from markdown content
import { GenerateSqlFromMermaid } from "@funktechno/little-mermaid-2-the-sql/lib/src/Library"; import { MarkdownContentResponseI } from "@funktechno/little-mermaid-2-the-sql/lib/src/types"; import { DbEntityAttributesDefinition, DbRelSpec } from "@funktechno/little-mermaid-2-the-sql/lib/src/types"; const markdownContent:MarkdownContentResponseI ={ settings: { database: "postgres", outputName: "result", isRaw: false, src: "" }, content:` #Test \`\`\`mermaid erDiagram %% comment 1 Persons { int PersonID PK "NOT NULL" varchar255 LastName varchar255 FirstName varchar255 Address varchar255 City } %% comment 2 Orders { int OrderID PK "NOT NULL" int PersonID FK "NOT NULL" } Persons ||--o{ Orders : "[Persons.PersonId] to [Orders.PersonId]" \`\`\` ` }; const sqlOutputs = GenerateSqlFromMermaid(markdownContent);
-
manual mermaid db model
import { DbParser } from "@funktechno/little-mermaid-2-the-sql/lib/src/generate-sql-ddl"; import erDb from "@funktechno/little-mermaid-2-the-sql/lib/src/mermaid/src/diagrams/er/erDb"; const db = erDb; let entityName = "Persons"; // load mermaid db with entities db.addEntity(entityName); let attributes:DbEntityAttributesDefinition[] = [ { attributeName: "PersonID", attributeKeyType: "PK", attributeType: "int", attributeComment: "NOT NULL" }, { attributeName: "LastName", attributeType: "varchar255" }, { attributeName: "FirstName", attributeType: "varchar255" }, { attributeName: "Address", attributeType: "varchar255" }, { attributeName: "City", attributeType: "varchar255" } ]; db.addAttributes(entityName,attributes); entityName = "Orders"; db.addEntity(entityName); attributes = [ { attributeName: "OrderID", attributeKeyType: "PK", attributeType: "int", attributeComment: "NOT NULL" }, { attributeName: "PersonID", attributeKeyType: "FK", attributeType: "int", attributeComment: "NOT NULL" } ]; db.addAttributes(entityName,attributes); const relSpec:DbRelSpec= { cardA: "ZERO_OR_MORE", cardB: "ONLY_ONE", relType: "IDENTIFYING" }; db.addRelationship("Persons", `[Persons.PersonId] to [${entityName}.PersonId]`, entityName, relSpec); const ddlSyntax = new DbParser('sqlite', db).getSQLDataDefinition();
-
sql output
CREATE TABLE "Persons" ( "City" varchar(255), "Address" varchar(255), "FirstName" varchar(255), "LastName" varchar(255), "PersonID" int NOT NULL, PRIMARY KEY("PersonID") ); CREATE TABLE "Orders" ( "PersonID" int NOT NULL, "OrderID" int NOT NULL, PRIMARY KEY("OrderID"), FOREIGN KEY ("PersonId") REFERENCES "Persons"("PersonId") );
-
- git clone repo
- run
git submodule update --init --recursive --progress
to clone submodule dependencies
- run
- run
npm install
inside directory. - Examples:
- sqlite
npm run littleMermaid2SQL -- -d sqlite --src samples/chinook-database-2.0.1.md
- postgres
npm run littleMermaid2SQL -- -d postgres --src samples/Adventureworks_pg.md
- mysql
npm run littleMermaid2SQL -- -d mysql --src samples/Adventureworks_mysql.md
- sqlite
- Force uninstall
npm uninstall -g little-mermaid-2-the-sql
npm list -g
littleMermaid2SQL --help
- test npm packaging
- update
.npmignore
- run
npm pack
unzip contents and verify, node_modules are not required b/c they will be installed with package.json npm unpublish @funktechno/little-mermaid-2-the-sql@0.0.5
can only work within 1 week of publish, not very useful b/c not possible to republish an unpublished version
- update