How do I store something from a conn.execute complete block?
https://docs.snowflake.com/en/user-guide/nodejs-driver-use.html#executing-statements
Basically I want to do something like this:
async function checkRecords(conn: Connection, sqlText: string): Promise<number> {
  return new Promise ((resolve, reject) => {
    try {
      conn.execute({
        sqlText: sqlText,
        complete: function(err, stmt, rows) {
          if (err) {
            reject(err);
          } else {
            let ret = parseInt(rows[0].COUNT);
            return Promise.resolve(ret);
          }
        }
      });
    } catch (err)  {
      error(err);
    }
  });
}
I think my question is similar to How can I execute Snowflake statement in async mode using NodeJs Snowflake driver? but I did not find any answer there.
Because of the async nature of the complete I never manage to return the value of the complete block.
I've tried to make it await, I've tried to make the function async and return a promise the point is that when I then call the function it still always ignores the wait (and I see in the log the executions with the actual result after my code that was supposed to wait for it already moved one).
Honestly I did not find any good example of this based in Snowflake SDK so I was wondering if anyone knows of a good example to test thigs.
I've seen a lot of different posts on javascript about this like How to return the response from an asynchronous call
But honestly I do not get it so I really wanted to know if someone has some example based on the Snowflake SDK I could use for inspiration.
I will close this question but somehow I can't make my code wait on the promise
Basically this code just does nothing.
  checkRecords(conn, stmtTextStage).then(value => {
    if (value > 0) {
      log(`STAGE.${name} contains ${value} unique records!`);
    } else {
      log(`STAGE.${name} contains no records!`, 'WARN');
    }
  });
