Created
March 8, 2022 21:35
-
-
Save cloverich/f6cd1770fb0feade7900a510fec30522 to your computer and use it in GitHub Desktop.
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
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