Skip to content

Instantly share code, notes, and snippets.

@cloverich
Created March 8, 2022 21:35
Show Gist options
  • Save cloverich/f6cd1770fb0feade7900a510fec30522 to your computer and use it in GitHub Desktop.
Save cloverich/f6cd1770fb0feade7900a510fec30522 to your computer and use it in GitHub Desktop.
import fs from "fs";
const lines = fs.readFileSync("./data.csv", "utf8").split("\n");
let idx = 0;
const asRecords: Array<Record<string, any>> = [];
while (lines.length) {
const line = lines.pop();
const [colId, colProp, colVal] = line!.split(",");
const colIdInt = parseInt(colId, 10);
if (asRecords[colIdInt]) {
asRecords[colIdInt][colProp] = colVal;
} else {
const record = { [colProp]: colVal };
asRecords[colIdInt] = record;
}
}
const tables: Record<string, any> = {};
for (const record of asRecords) {
let table;
if (record.table_name in tables) {
table = tables[record.table_name];
} else {
table = {};
tables[record.table_name] = table;
}
if (table[record.column_name]) {
table[record.column_name] = {
// ..._.pick()
};
} else {
}
}
console.log(asRecords);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment