gajus / slonik

A Node.js PostgreSQL client with runtime and build time type safety, and composable SQL.
Other
4.56k stars 138 forks source link

anyFirst method returning error if we have multiple columns #630

Closed satyam9798 closed 2 months ago

satyam9798 commented 2 months ago

anyFirst method returning error if we have multiple columns

Expected Behavior

Should return first column values if we have multiple columns in our table.

Current Behavior

Throws error if we have number of column not equals to zero (even if it is greater than 1)

Possible Solution

Incorrect implementation:

const firstRow = rows[0]; const keys = Object.keys(firstRow); if (keys.length !== 1) { log.error({ queryId, }, 'result row has no columns'); throw new errors_1.DataIntegrityError(query); }

correct implementation:

 if (keys.length === 0) {
    log.error({
        queryId,
    }, 'result row has no columns');
    throw new errors_1.DataIntegrityError(query);
}

Steps to Reproduce

  1. Create a database and a table with multiple columns.
  2. use anyFirst method to retreive the values of first column 3.If the table has multiple columns it will throw an error

Logs

DataIntegrityError: Query returned an unexpected result. at anyFirst (...\node_modules\slonik\dist\connectionMethods\anyFirst.js:19:15)