Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var importJson = require("./MOCK_DATA.json");
- var sqlite3 = require('sqlite3').verbose();
- var db = new sqlite3.Database('sqlitedb.db');
- console.log("Hello! we're about to populate the data in here. we'll use MOCK_DATA.json");
- // console.log(importJson);
- db.serialize(function() {
- // Prepared statement
- var stmt = db.prepare("INSERT INTO parts VALUES (?,?)");
- importJson.forEach(element => {
- stmt.run(element.id, {element} )
- })
- // Lets send it to the database
- stmt.finalize(
- (err) => {
- if (err) {
- return console.error(err.message);
- }
- });
- });
- // // Add each row
- // importJson.forEach(element => {
- // console.log(`Inserting for ${element.name}`)
- // db.prepare('INSERT INTO parts (id,data) VALUES (?,?)', element.id, [
- // {
- // "id": "1234abcd",
- // "name": "3mm Screw 15mm",
- // "description": "For projects to hold parts together.",
- // "hidden": false
- // }
- // ]);
- // });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement