-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
33 lines (29 loc) · 982 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const pool=require('./db/dbConnection');
const fs=require('fs');
const { STATUS_CODES } = require('http');
const stringData=fs.readFileSync("./datas/subjects.json",
{encoding:'utf8', flag:'r'});
const rawData=JSON.parse(stringData);
//console.log(rawData);
const newData=[];
for (const row of rawData)
{
const {code, name,m1,m2}=row;
const newRow=[code,name,m1,m2,40];
const newObj={
subject_code:code,
title:name,
theory_fm:m1,
practical_fm:m2,
pass_percentage:40
}
newData.push(newRow);
}
// pool.execute('INSERT INTO subject SET subject_code=?,title=?,theory_fm=?,practical_fm=?,pass_percentage=?',newData).then(data=>{
// console.log("inserted");
// }).catch(err=>console.log(err));
for (data of newData){
pool.execute('INSERT INTO subject(subject_code,title,theory_fm,practical_fm,pass_percentage) values(?,?,?,?,?)',data).then(data=>{
console.log("inserted");
}).catch(err=>console.log(err));
}