Description
Please answer these questions before submitting your issue.
In order to accurately debug the issue this information is required. Thanks!
-
What version of NodeJS driver are you using?
1.9.0 -
What operating system and processor architecture are you using?
Mac M2 -
What version of NodeJS are you using?
(node --version
andnpm --version
)
v21.6.0 -
What are the component versions in the environment (
npm list
)?
5.Server version:* E.g. 1.90.1
You may get the server version by running a query:
SELECT CURRENT_VERSION();
- What did you do?
snowflake.createConnection() receives a config object that specifies a key/value for the session parameter.
const snowflake = require('snowflake-sdk');
const createSnowflakeConnectionWithSessionVar = (orgKey, orgValue) => {
const {
SNOWFLAKE_ACCOUNT_IDENTIFIER,
SNOWFLAKE_USERNAME,
SNOWFLAKE_PASSWORD,
} = require('../utils/config');
// Create a new connection
const connection = snowflake.createConnection({
account: SNOWFLAKE_ACCOUNT_IDENTIFIER,
username: SNOWFLAKE_USERNAME,
password: SNOWFLAKE_PASSWORD,
application: 'CORE_PLATFORM',
clientSessionKeepAlive: true,
clientSessionKeepAliveHeartbeatFrequency: 3600,
sessionParameters: {
[orgKey]: orgValue,
},
});
// Return a Promise that resolves with the connection
return new Promise((resolve, reject) => {
connection.connect((err, conn) => {
if (err) {
reject(err);
} else {
resolve(conn);
}
});
});
};
module.exports = createSnowflakeConnectionWithSessionVar;
Usage in backend middleware function:
try {
const conn = await createSnowflakeConnectionWithSessionVar('client', org);
conn.execute({
sqlText: query,
complete: function (err, stmt, rows) {
if (err) {
console.error('Failed to execute query', err);
next(err);
} else {
const random = rows.map((row) => row.RANDOM);
res.locals.random = random;
next();
}
conn.destroy((err, conn) => {
if (err) {
console.error('Failed to close connection', err);
}
});
},
});
} catch (error) {
console.error('Connection error', error);
next(error);
}
- What did you expect to see?
I expected the session parameter to be set to whatever I call this function with. Instead, the session parameter remains undefined. I looked through the API documentation and can't seem to find how to do this.
Snowflake Session Variables
What should have happened and what happened instead?
-
Can you set logging to DEBUG and collect the logs?
https://community.snowflake.com/s/article/How-to-generate-log-file-on-Snowflake-connectors
e.g
Add this to get standard output.
var snowflake = require('snowflake-sdk');
snowflake.configure(
{
logLevel: 'trace'
});
- What is your Snowflake account identifier, if any? (Optional)
Activity