Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default functionality / Run #24

Open
thxmike opened this issue Sep 20, 2015 · 0 comments
Open

Default functionality / Run #24

thxmike opened this issue Sep 20, 2015 · 0 comments

Comments

@thxmike
Copy link

thxmike commented Sep 20, 2015

Based on the documentation:
"A pump reads data from its input buffer or stream and copies it to the output buffer by default:"
If I use the following example:
var datapumps = require('datapumps');
var mssql = require('mssql');
Promise = require('bluebird');

var config = {
user: 'user',
password: 'pw',
server: 'server', // You can use 'localhost\instance' to connect to named instance
database: 'db',
stream: true, // You can enable streaming globally
requestTimeout: 60000,
options: {
encrypt: false // Use this if you're on Windows Azure
}
}

var connection = new mssql.Connection(config, function (err) {

if (err) {
    console.log(err);
    return;
}

var request = connection.request();

//Only executed if not streaming i.e streaming = false
request.query('some query', function (err, recordset) {
    // ... error checks
    if (err) {
        console.log(err);
    }
});

//All Event Emitters are used when streaming i.e streaming = true
request.on('recordset', function (columns) {
    // Emitted once for each recordset in a query
});

request.on('row', function (row) {
    // Emitted for each row
    extract_input_buffer.writeAsync(row);

    console.log(extract_input_buffer.content.length);
});

request.on('error', function (err) {
    // May be emitted multiple times
});

request.on('done', function (returnValue) {
    // Always emitted as the last one
    connection.close();
    extract_input_buffer.seal();

});

});

var extract_pump = new datapumps.Pump();

var extract_input_buffer = new datapumps.Buffer({size: 100});

var extract_output_buffer = extract_pump.buffer();

extract_pump.errorBuffer().on('write', function (data) {
console.log(data);
});

extract_pump.buffer('output').on('write', function (data) {
console.log(extract_output_buffer.content.length);
});

extract_pump.buffer('output').on('end', function (data) {
console.log("output buffer has ended")
});

var transform_pump = new datapumps.Pump();

extract_pump
.from(extract_input_buffer)
.to(transform_pump, 'output')
.logErrorsToConsole()
.run()
.then(function(){

    console.log(extract_output_buffer);
});

transform_pump
.logErrorsToConsole()
.run()
.then(function () {
var from1buffer = extract_pump.from();
var output1buffer = extract_pump.buffer('output');
var from2buffer = transform_pump.from();
var output2buffer = transform_pump.buffer('output');
console.log(from1buffer.content.length);
console.log(output1buffer.content.length);
console.log(from2buffer.content.length);
console.log(output2buffer.content.length);
});

I see the extract_output_buffer written to, in line 66, however it is not being picked up in the transform_pump. Based on line 81 I set the transform_pump input buffer to the output buffer of extract_pump.

What am I am missing? Can you clarify?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant