json-to-sql-script

0.2.0 • Public • Published

JSON to SQL script

This package creates SQL script from JSON-file.

Install

npm i -g json-to-sql-script

Arguments

'-s': '--source' // Source file path (required)
'-o': '--output' // Output file path (required)
'-n': '--name' // Main table name (required)
'-e': '--excludes' // Exclude property names

Example

json-to-sql-script -s 'input.json' -o 'output.sql' -n 'items' -e 'date_created|date_modified'

Example output

{
  "data": [
    {
      "name": "Rye bread",
      "description": "Rye bread is a type of bread made with various proportions of flour from rye grain."
    },
    {
      // next object
    }
  ]
}
INSERT IGNORE INTO items (name,description) VALUES ("Rye bread","Rye bread is a type of bread made with various proportions of flour from rye grain.");

If JSON object includes arrays or objects, for example:

{
  "data": [
    {
      "name": "Rye bread",
      "description": "Rye bread is a type of bread made with various proportions of flour from rye grain.",
      "components": [
        {
          "name": "Salt"
        },
        {
          "name": "Sugar"
        }
      ]
    },
    {
      // next object
    }
  ]
}

Script adds rows with ref_{{table_name}}_name:

INSERT IGNORE INTO items_components (name,ref_item_name) VALUES ("Salt","Rye bread.");

Readme

Keywords

Package Sidebar

Install

npm i json-to-sql-script

Weekly Downloads

0

Version

0.2.0

License

ISC

Unpacked Size

5.55 kB

Total Files

6

Last publish

Collaborators

  • tertiumnon