Skip to content

Instantly share code, notes, and snippets.

@Prajwalprakash3722
Created March 30, 2023 08:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Prajwalprakash3722/371615a3d6d7c25b2c20d1be8451203f to your computer and use it in GitHub Desktop.
Save Prajwalprakash3722/371615a3d6d7c25b2c20d1be8451203f to your computer and use it in GitHub Desktop.
For Migrating Alumini Data to SQL Statements
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);
@Prajwalprakash3722
Copy link
Author

copy the data from links.js, run the file and pipe the output to a sql file that’s it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment