/** * The data result constructor * @param {Array} result An API response individual result * @param {Array} [valuesIndex] The index to get the values from the result */ constructor (result, valuesIndex) { if (typeof result !== 'object') { throw new Error('The result argument is required to be an object') } if (typeof valuesIndex !== 'undefined' && !Number.isFinite(valuesIndex)) { throw new Error('The valuesIndex argument is required to be a finite number when provided') } this.time = result.time this.rowsAffected = result.rows_affected this.lastInsertId = result.last_insert_id // Map the values array to an object where columns are the properties if (Number.isFinite(valuesIndex)) { const { columns } = result const resultValues = result.values[valuesIndex] if (resultValues) { this.data = resultValues.reduce((acc, val, i) => { const col = columns[i] acc[col] = val return acc }, {}) } } }