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

Run / Custom Output buffer #25

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

Run / Custom Output buffer #25

thxmike opened this issue Sep 20, 2015 · 0 comments

Comments

@thxmike
Copy link

thxmike commented Sep 20, 2015

In the following example
var datapumps = require('datapumps');
var mssql = require('mssql');
Promise = require('bluebird');

var config = {
user: 'use',
password: 'pw',
server: 'svrp', // 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('somequery', 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});

extract_pump.buffers(
{test_output_buffer: extract_pump.createBuffer()}
);

test_output_buffer = extract_pump.buffer('test_output_buffer');

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

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

extract_pump.buffer('test_output_buffer').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, 'test_output_buffer')
.logErrorsToConsole()
.run()
.then(function(){

    console.log(test_output_buffer);
});

transform_pump
.logErrorsToConsole()
.run()
.then(function () {
var from1buffer = extract_pump.from();
var output1buffer = extract_pump.buffer('test_output_buffer');
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 create a custom buffer in the extract pump, however it appears when using "run()", it cannot find the 'output' buffer in the extract_pump and reports an error:

{ error: [Error: No such buffer: output], pump: null }
Error in pump (root): Error: No such buffer: output

Can you create custom buffers and use the default execution of "run()", or do you have to override the process() function and use start() when creating custom buffers?

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