Convenient methods for handling mysql2 query results. There are methods for dealing with a variety of expected results, which throw an error if the expectations are not met, and return the resulting query data.
Expects an array of results, such as from a SELECT, not from using the mysql package multipleStatements option. An empty array counts as an expected result. Pass false
as the second arg to not throw an error.
Returns the array of results.
Expects a single result. Pass false
as the second arg to not throw an error.
Returns the single result object.
Expects dbQueryResult.affectedRows
to be a number greater than zero, such as when executing a DELETE query. Optionally specify a number if expecting a specific number of affected rows.
Returns undefined
.
Expects dbQueryResult.changedRows
to be a number greater than zero, such as when executing an UPDATE query. Optionally specify a number if expecting a specific number of affected rows. Returns the query result data.
Returns undefined
.