When a MySQL Query is executed in Node.js, an object called Result Object is returned to the callback function. The Result Object contains result set or properties that provide information regarding the execution of a query in MySQL Server.

Node.js MySQL Result Object

The contents of Result Object depends on the SQL query made to MySQL Server. Following table contents describe the result object for queries like select, insert, update and delete.

MySQL QueryResult Object
SELECT FROMResult Set containing Record
INSERT INTOObject containing Execution Status
UPDATEObject containing Execution Status
DELETE FROMObject containing Execution Status

We shall see how to access properties of records in a result set and how to access properties of execution status with the help of following examples.

Example – MySQL SELECT FROM Query – Accessing ResultSet

We can access the records in Result Set as an array and properties of a record using DOT (.) Operator.

Run the above program using node in Terminal

Example – MySQL INSERT INTO Query

We can access the properties of a Result Object using DOT (.) Operator.

Run the above program using node in Terminal

Example – MySQL UPDATE Query

We can access the properties of a Result Object using DOT (.) Operator.

Run the above program using node in Terminal

Example – MySQL DELETE FROM Query

We can access the properties of a Result Object using DOT (.) Operator.

Run the above program using node in Terminal

Conclusion

In this Node.js Tutorial – Node.js MySQL – Result Object, we have learnt to access records of a result set and also went through examples to access properties of result object containing information about query execution.