Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
Reject if rowcount == 0 in a post request using tedious

Hello im having trouble rejecting my promise if my request has rowcount == 0, how can i reject if my sql statement returns no rows? Even if it returns 0 rows it resolves.

This is my code

function login(body) {
    return new Promise((resolve, reject) => {   
        var connection = new Connection(config)
        connection.on('connect', function(err){
            if (err){
                 reject(err)
                 console.log(err);
            } 
            else {
               const request = new Request(`SELECT * FROM dba.[user]  WHERE username = '${body.username}' and password = '${body.password}'`, function(err, rowCount){
                    if (err){
                        reject("Sorry not possible")
                    }
                    else if (rowCount == 0) {
                        console.log(rowCount+'rows')
                        reject("No rows returned")
                    }
                })
                var counter = 1
                response = {}
                connection.execSql(request)
                request.on('row', function(columns){
                    response[counter] = {}
                    columns.forEach(function(column){
                         response[counter][column.metadata.colName] = column.value
                    });
                    counter += 1 
                });
                request.on('doneInProc', function () {
                    resolve(response)
                })
            }         
        })
         connection.connect()        
    }) 
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!