ohadinho
ohadinho

Reputation: 7144

'OkPacket' in mysql module of node.js

I'm trying to get results by each row from mysql table:

query.on('result', function(row) {
            connection.pause();
            console.log('First Name: ', row.FirstName);
                console.log('Last Name: ', row.LastName);
            connection.resume();
        });

The problem is that the last row I get is an 'OkPacket'.

What is the right way to check the last packet ?

Upvotes: 1

Views: 6012

Answers (1)

ohadinho
ohadinho

Reputation: 7144

I used ".constructor.name" in order to check it's a RowDataPacket and not an OkPacket:

 function onGeneratedRow(row,connection) {
            if(row.constructor.name == 'RowDataPacket') {
                console.log('First Name: ', row.FirstName);
                console.log('Last Name: ', row.LastName);           
            }
        }

Upvotes: 6

Related Questions