Skip to main content

Executing a Statement

This comparison shows the difference between callback-based and Promise-based query execution.

Without this library: Use callbacks to handle execution results, leading to unpredictable code execution order.

With this library: Simply await the execution result with predictable, sequential code flow.

Examples

tip
  • Click “WITHOUT Helper Library” to see the original code
  • Click “WITH Helper Library” to see the improved code using this library

Adapted from an example in the Snowflake SDK documentation.

// Not using the Promise Helper Library

const statement = connection.execute({
sqlText: 'CREATE DATABASE testdb',
complete: function(err, stmt, rows) {
if (err) {
console.error('Failed to execute statement:', err.message);
return;
}
console.log('Successfully executed statement: ' + stmt.getSqlText());
}
});

// This executes immediately, before the query completes!
console.log('This will likely execute before completion due to async behavior!');