'Await inside nodejs snowflake stream.on('data', fn)

I want to process the data stream and insert it in DB synchronously. How can do it. If I pass an async function to stream.on it won't be processed synchronously.

return new Promise(async (resolve, reject) => {
    logger.info("Initiating snowflake connection")
    const connection = await getConnection();
    const statement = await connection.execute({
        sqlText: 'SELECT * FROM CMO_DATA;',
        complete: function (err, stmt, rows) {
            var stream = statement.streamRows();
            stream.on('data', async function (row) {
                logger.info("Processing data =>", row)
                await SnowflakeData.insertOne(row);
                count++;
            });
            stream.on('end', function () {
                logger.info('All rows consumed =>', count);
                resolve()
            });
            stream.on('error', function (err) {
                logger.error('Failed to consume all rows', err);
                reject(err)
            });
        }
    });
})


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source