GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - funktechno/sql-simple-parser: sql ddl parser to support extensions for drawio

BranchesTags
Open more actions menu

Latest commit

 

History

139 Commits
139 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.vscode
.vscode
 
 
build
build
 
 
client
client
 
 
examples
examples
 
 
scripts
scripts
 
 
src
src
 
 
tests
tests
 
 
.eslintignore
.eslintignore
 
 
.eslintrc
.eslintrc
 
 
.gitignore
.gitignore
 
 
.npmignore
.npmignore
 
 
GitVersion.yml
GitVersion.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
jest.config.ts
jest.config.ts
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

sql-simple-parser

sql ddl parser to support extensions for drawio

Getting started

  • npm install --save @funktechno/sqlsimpleparser
  • how to use:
import { SqlSimpleParser } from "@funktechno/sqlsimpleparser"

var sql = `CREATE TABLE "humanresources_department" (
	"departmentid" serial NOT NULL,
	"name" Name NOT NULL,
	"groupname" Name NOT NULL,
	"modifieddate" timestamp NOT NULL,
	PRIMARY KEY("departmentid")
);

CREATE TABLE "humanresources_employeedepartmenthistory" (
  "businessentityid" int(4) NOT NULL,
  "departmentid" int(2) NOT NULL,
  "shiftid" int(2) NOT NULL,
  "startdate" date NOT NULL,
  "enddate" date,
  "modifieddate" timestamp NOT NULL,
  PRIMARY KEY("businessentityid","departmentid","shiftid","startdate"),
  FOREIGN KEY ("departmentid") REFERENCES "humanresources_department"("departmentid")
);
`

// run parser
const parser = new SqlSimpleParser('postgres')

// get models
const models = parser
  .feed(sql)
  .ToModel();
  • outputs
{
  "TableList": [
    {
      "Name": "humanresources_department",
      "Properties": [
        {
          "Name": "departmentid",
          "ColumnProperties": "serial NOT NULL",
          "TableName": "humanresources_department",
          "ForeignKey": [
            {
              "PrimaryKeyTableName": "humanresources_employeedepartmenthistory",
              "PrimaryKeyName": "departmentid",
              "ReferencesPropertyName": "departmentid",
              "ReferencesTableName": "humanresources_department",
              "IsDestination": true
            }
          ],
          "IsForeignKey": false,
          "IsPrimaryKey": true
        },
        {
          "Name": "name",
          "ColumnProperties": "Name NOT NULL",
          "TableName": "humanresources_department",
          "ForeignKey": [],
          "IsForeignKey": false,
          "IsPrimaryKey": false
        },
        {
          "Name": "groupname",
          "ColumnProperties": "Name NOT NULL",
          "TableName": "humanresources_department",
          "ForeignKey": [],
          "IsForeignKey": false,
          "IsPrimaryKey": false
        },
        {
          "Name": "modifieddate",
          "ColumnProperties": "timestamp NOT NULL",
          "TableName": "humanresources_department",
          "ForeignKey": [],
          "IsForeignKey": false,
          "IsPrimaryKey": false
        }
      ]
    },
    {
      "Name": "humanresources_employeedepartmenthistory",
      "Properties": [
        {
          "Name": "businessentityid",
          "ColumnProperties": "int(4) NOT NULL",
          "TableName": "humanresources_employeedepartmenthistory",
          "ForeignKey": [],
          "IsForeignKey": false,
          "IsPrimaryKey": true
        },
        {
          "Name": "departmentid",
          "ColumnProperties": "int(2) NOT NULL",
          "TableName": "humanresources_employeedepartmenthistory",
          "ForeignKey": [
            {
              "PrimaryKeyTableName": "humanresources_department",
              "PrimaryKeyName": "departmentid",
              "ReferencesPropertyName": "departmentid",
              "ReferencesTableName": "humanresources_employeedepartmenthistory",
              "IsDestination": false
            }
          ],
          "IsForeignKey": true,
          "IsPrimaryKey": true
        },
        {
          "Name": "shiftid",
          "ColumnProperties": "int(2) NOT NULL",
          "TableName": "humanresources_employeedepartmenthistory",
          "ForeignKey": [],
          "IsForeignKey": false,
          "IsPrimaryKey": true
        },
        {
          "Name": "startdate",
          "ColumnProperties": "date NOT NULL",
          "TableName": "humanresources_employeedepartmenthistory",
          "ForeignKey": [],
          "IsForeignKey": false,
          "IsPrimaryKey": true
        },
        {
          "Name": "enddate",
          "ColumnProperties": "date",
          "TableName": "humanresources_employeedepartmenthistory",
          "ForeignKey": [],
          "IsForeignKey": false,
          "IsPrimaryKey": false
        },
        {
          "Name": "modifieddate",
          "ColumnProperties": "timestamp NOT NULL",
          "TableName": "humanresources_employeedepartmenthistory",
          "ForeignKey": [],
          "IsForeignKey": false,
          "IsPrimaryKey": false
        }
      ]
    }
  ],
  "Dialect": "postgres",
  "ForeignKeyList": [
    {
      "PrimaryKeyTableName": "humanresources_employeedepartmenthistory",
      "PrimaryKeyName": "departmentid",
      "ReferencesPropertyName": "departmentid",
      "ReferencesTableName": "humanresources_department",
      "IsDestination": true
    },
    {
      "PrimaryKeyTableName": "humanresources_department",
      "PrimaryKeyName": "departmentid",
      "ReferencesPropertyName": "departmentid",
      "ReferencesTableName": "humanresources_employeedepartmenthistory",
      "IsDestination": false
    }
  ],
  "PrimaryKeyList": [
    {
      "PrimaryKeyTableName": "humanresources_department",
      "PrimaryKeyName": "departmentid"
    },
    {
      "PrimaryKeyTableName": "humanresources_employeedepartmenthistory",
      "PrimaryKeyName": "businessentityid"
    },
    {
      "PrimaryKeyTableName": "humanresources_employeedepartmenthistory",
      "PrimaryKeyName": "departmentid"
    },
    {
      "PrimaryKeyTableName": "humanresources_employeedepartmenthistory",
      "PrimaryKeyName": "shiftid"
    },
    {
      "PrimaryKeyTableName": "humanresources_employeedepartmenthistory",
      "PrimaryKeyName": "startdate"
    }
  ]
}
  • there are some example sql files
  • see test examples_models.spec for more use cases

Supported

  • Databases: sqlite, postgres, sqlserver, mysql
  • table names, primary keys, foreign keys, column names with extended column information

Development

  • npm install
  • npm test or use vscode debugger Jest single run

Deploy

  • npm publish --access public
  • Testing
    • npm pack

About

sql ddl parser to support extensions for drawio

www.npmjs.com/package/@funktechno/sqlsimpleparser

Topics

drawioerdiagramhacktoberfestmssqlmysqlpluginspostgressqlsql-ddlsql-parsersqlite

Resources

Readme
MIT license
Activity
Custom properties

Stars

2 stars

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.