npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@funktechno/little-mermaid-2-the-sql

v0.1.0

Published

* a command line tool for generating create sql from mermaid erDiagram

Downloads

18

Readme

little-mermaid-2-the-sql

  • a command line tool for generating create sql from mermaid erDiagram

Getting Started

  1. npm install -g @funktechno/little-mermaid-2-the-sql
  2. littleMermaid2SQL --help
  3. littleMermaid2SQL -d dbType --src markdownFilePath

Generating Mermaid erDiagram

Ala Cart

  1. npm install --save @funktechno/little-mermaid-2-the-sql
  2. 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")
      );

Development

  1. git clone repo
    1. run git submodule update --init --recursive --progress to clone submodule dependencies
  2. run npm install inside directory.
  3. Examples:
    1. sqlite npm run littleMermaid2SQL -- -d sqlite --src samples/chinook-database-2.0.1.md
    2. postgres npm run littleMermaid2SQL -- -d postgres --src samples/Adventureworks_pg.md
    3. mysql npm run littleMermaid2SQL -- -d mysql --src samples/Adventureworks_mysql.md
  4. Force uninstall
    • npm uninstall -g little-mermaid-2-the-sql
    • npm list -g
    • littleMermaid2SQL --help
  5. 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/[email protected] can only work within 1 week of publish, not very useful b/c not possible to republish an unpublished version

Technologies