-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from anct-cnum/Creation_extract_cras_outil_prefet
Création d'export de cras car metabase est limité à 1M de ligne
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const { program } = require('commander'); | ||
const { execute } = require('../utils'); | ||
|
||
require('dotenv').config(); | ||
|
||
execute(__filename, async ({ logger, dbDatalake }) => { | ||
program.helpOption('-e', 'HELP command'); | ||
program.parse(process.argv); | ||
|
||
const cursor = await dbDatalake.collection('cras').find(); | ||
|
||
logger.info(`Generating CSV file...`); | ||
let csvFile = path.join(__dirname, '../../../data/exports', `cras.csv`); | ||
let file = fs.createWriteStream(csvFile, { flags: 'w' }); | ||
|
||
file.write(`ID;ConseillerId;Cra;CreatedAt;UpdatedAt;PermanenceId;StructureId\n`); | ||
while (await cursor.hasNext()) { | ||
const cra = await cursor.next(); | ||
file.write(`${cra._id};${cra.conseillerId};${JSON.stringify(cra.cra)};${cra.createdAt};${cra.updatedAt};${cra.permanenceId};${cra.structureId};\n`); | ||
} | ||
|
||
file.close(); | ||
}); |