@giorgi-g/csv-parser
Version:
CSV parser for migrations with Sequelizer
44 lines (43 loc) • 1.85 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const CSVParser_1 = require("./src/lib/CSVParser");
const File_1 = require("./src/lib/File");
const cSVParserOptions = {
classPath: "../entities/Profile",
mapKeyIndexes: [1],
mergeMapKeyValues: true,
};
const csvParser = new CSVParser_1.CSVParser("sample_profiles", cSVParserOptions);
csvParser.Read().then((response) => __awaiter(void 0, void 0, void 0, function* () {
const filePath = './src/logs/every-tenth-id';
const everyTenthProfile = [];
const file = new File_1.File(filePath);
response.forEach((item, index) => {
if (Array.isArray(item)) {
console.log('item', item);
}
else {
if (item.profile.id % 100 === 0) {
everyTenthProfile.push(item.profile);
}
if (index === response.size - 1) {
file.write(everyTenthProfile).then(() => {
file.read().then(r => {
console.log('r', r);
});
});
}
}
});
})).catch((err) => {
console.log('err', err);
});