Created
March 30, 2023 08:25
-
-
Save Prajwalprakash3722/371615a3d6d7c25b2c20d1be8451203f to your computer and use it in GitHub Desktop.
For Migrating Alumini Data to SQL Statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sids = { | |
main: 0, | |
compsoc: 1, | |
comsoc: 2, | |
pes: 3, | |
aps: 4, | |
sps: 5, | |
ras: 6, | |
wie: 7, | |
sight: 8, | |
cas: 9, | |
sc: 10, | |
}; | |
let sql = `INSERT INTO execom_members (sid, firstName, lastName, position, imagePath, tenureStart, tenureEnd) VALUES `; | |
Object.keys(alumni).forEach((key) => { | |
const sid = sids[key]; | |
const soc = key; | |
const members = alumni[key]; | |
Object.keys(members).forEach((key) => { | |
const year = key; | |
const members = alumni[soc][year]; | |
members.forEach((member) => { | |
const name = member.name.split(" "); | |
const firstName = name[0]; | |
// remaining names are last name | |
const lastName = name.slice(1).join(" "); | |
const position = member.position; | |
const imagePath = member.image ?? ""; | |
const tenureStart = `${year}-01-05`; | |
const tenureEnd = `${parseInt(year) + 1}-01-04`; | |
sql += `(${sid}, '${firstName}', '${lastName}', '${position}', '${imagePath}', '${tenureStart}', '${tenureEnd}'),`; | |
}); | |
}); | |
}); | |
sql = sql.slice(0, -1); | |
sql += ";"; | |
console.log(sql); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
copy the data from links.js, run the file and pipe the output to a sql file that’s it :)