This package creates SQL script from JSON-file.
npm i -g json-to-sql-script
'-s': '--source' // Source file path (required)
'-o': '--output' // Output file path (required)
'-n': '--name' // Main table name (required)
'-e': '--excludes' // Exclude property names
json-to-sql-script -s 'input.json' -o 'output.sql' -n 'items' -e 'date_created|date_modified'
{
"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.");