Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- var fs = require('fs');
- var Connection = require('tedious').Connection;
- var Request = require('tedious').Request;
- var config = {
- server: 'DEV01',
- userName: 'sa',
- password: '10vs@kbsc',
- 'options': {
- 'database': 'KonektArquivos',
- 'instanceName': 'KBDFIDC'
- }
- };
- var connection = new Connection(config);
- connection.on('connect', function(err) {
- console.log('connected');
- get_xmls();
- }
- );
- connection.on('debug', function(err) { console.log('debug:', err);});
- function get_xmls() {
- var request = new Request(`
- SELECT TOP 200 n.Chave, a.danfe
- FROM NfeArquivo a
- INNER JOIN Nfe n ON n.id = a.id
- ORDER BY a.id DESC;`, function(err, rowCount) {
- if (err) {
- console.log(err);
- }
- });
- request.on('row', function(columns) {
- var chave = columns[0].value;
- var xml = columns[1].value;
- fs.writeFile('xml/' + chave + '.xml', xml, function (err) {
- if (err) throw err;
- console.log(chave + ' Saved!');
- });
- });
- request.on('done', function(rowCount, more) {
- console.log(rowCount + ' rows returned');
- connection.close();
- });
- connection.execSql(request);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement