-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimportarFinanciador.ts
More file actions
100 lines (80 loc) · 2.62 KB
/
importarFinanciador.ts
File metadata and controls
100 lines (80 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { servicioMongo } from './servicioMongo';
import { servicioSips } from './servicioSips'
import * as sql from 'mssql';
import * as mongodb from 'mongodb';
import * as config from './config';
import { debug } from 'util';
import * as assert from 'assert';
import * as consultas from './consultas';
var srvSips = new servicioSips();
var srvMongo = new servicioMongo();
const connection = {
user: config.user,
password: config.password,
server: config.serverSql,
database: config.databasePadron,
};
const url = config.urlMigracion;
sql.connect(connection, err => {
// ... error checks
const request = new sql.Request()
request.stream = true // You can set streaming differently for each request
request.query(consultas.consultaFinanciador) // or request.execute(procedure)
request.on('recordset', columns => {
// Emitted once for each recordset in a query
console.log(columns);
})
request.on('row', row => {
// Emitted for each row in a recordset
(async function() {
let client;
try {
client = await mongodb.MongoClient.connect(url);
console.log("Connected correctly to server");
const db = client.db('andes');
let r = await db.collection('financiador').insertOne(row);
assert.equal(1, r.insertedCount);
} catch (err) {
console.log(err.stack);
}
// Close connection
client.close();
})();
})
request.on('error', err => {
// May be emitted multiple times
console.log('Error al guardar', err);
})
request.on('done', result => {
// Always emitted as the last one
console.log('FIN', result);
})
})
sql.on('error', err => {
// ... error handler
console.log('Error de conexión', err);
})
/*
Este codigo funciona, el de arriba tambien
srvSips.obtenerDatosFinanciador()
.then((resultado) => {
if (resultado == null) {
console.log('Sin datos de financiador');
} else {
var list;
list = resultado[0];
//console.log(resultado);
srvMongo.borrarCollection('financiador');
srvMongo.guardarDatos(list, 'financiador')
.then((res => {
console.log('Guardar Financiador');
}))
.catch((err => {
console.log('Error al guardar Financiador', err);
}))
}
})
.catch((err) => {
console.error('Error**:' + err)
});
*/