Skip to content

Commit

Permalink
SNOW-1300062: Cleanup samples (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pbulawa authored Apr 5, 2024
1 parent 0811a5b commit ec00a1d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
{
'files': ['samples/*.js'],
'rules': {
'no-console': ['warn'],
'no-console': ['off'],
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions samples/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
********************************************************************************
NodeJS Driver - Samples
Node.js Driver - Samples
********************************************************************************

Install
Expand Down Expand Up @@ -41,7 +41,7 @@ npm run jsonParserComparison
Test can be started with parameters:
- number of rows in table, default=300000
- number of selected rows, default=300000
- only for choosen parser if got as last parameter: Function, vm, better-eval, JSON, default all
- only for chosen parser if got as last parameter: Function, vm, better-eval, JSON, default all

Example:
```
Expand Down
17 changes: 8 additions & 9 deletions samples/jsonParserComparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ async function run() {
const defaultRowCount = 300000;
const rowCountToInsert = process.argv[2];
const rowCountToFetch = process.argv[3];
const choosenParser = process.argv[4];
const chosenParser = process.argv[4];
console.log('Started with arguments: ');
console.log(`Inserted rows amount: ${rowCountToInsert} - default ${defaultRowCount}`);
console.log(`Selected rows amount: ${rowCountToFetch} - default ${defaultRowCount}`);
console.log(`Selected json parse : ${choosenParser} - default all of Function, vm, better-eval, JSON`);
console.log(`Selected json parser: ${chosenParser} - default all of Function, vm, better-eval, JSON`);

const rowCount = rowCountToInsert || defaultRowCount;
const selectLimit = rowCountToFetch || defaultRowCount;
Expand All @@ -23,7 +23,7 @@ async function run() {
"guid": "e7e0e5d8-82b4-47f7-a2ab-68588c93d81e",
"isActive": false,
"balance": "$2,611.69",
"picture": "http://placehold.it/32x32",
"picture": "https://placehold.it/32x32",
"age": 21,
"eyeColor": "blue",
"name": "Joanna Atkinson",
Expand Down Expand Up @@ -73,20 +73,20 @@ async function run() {
const selectCountVariant = (tableName) => `select count(colA) from ${(tableName)}`;

const testCases = [];
if (!choosenParser || choosenParser.toString().includes('Function')) {
if (!chosenParser || chosenParser.toString().includes('Function')) {
testCases.push({ parser: 'Function', jsonColumnVariantParser: (rawColumnValue) => new Function(`return (${rawColumnValue})`) });
}
if (!choosenParser || choosenParser.toString().includes('better-eval')) {
if (!chosenParser || chosenParser.toString().includes('better-eval')) {
testCases.push({ parser: 'betterEval', jsonColumnVariantParser: (rawColumnValue) => require('better-eval').call('(' + rawColumnValue + ')') });
}
if (!choosenParser || choosenParser.toString().includes('vm')) {
if (!chosenParser || chosenParser.toString().includes('vm')) {
testCases.push({ parser: 'vm', jsonColumnVariantParser: rawColumnValue => require('vm').runInNewContext('(' + rawColumnValue + ')') });
}
// eval lib contains vulnerability so we decide to resign using it
// if (!process.argv[4] || process.argv[4].toString().contains('eval')) {
// testCases.push({parser: 'eval', jsonColumnVariantParser: rawColumnValue => eval('(' + rawColumnValue + ')')})
// };
if (!choosenParser || choosenParser.toString().includes('JSON')) {
if (!chosenParser || chosenParser.toString().includes('JSON')) {
testCases.push({ parser: 'JSON', jsonColumnVariantParser: rawColumnValue => JSON.parse(rawColumnValue) });
}

Expand Down Expand Up @@ -181,5 +181,4 @@ async function run() {
}, Promise.resolve());
}

run();

run().catch((err) => console.error(err));
3 changes: 1 addition & 2 deletions samples/rowsVsStreamingQuery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
const snowflake = require('snowflake-sdk');
const { connectUsingEnv, destroyAsync } = require('./helpers');

Expand Down Expand Up @@ -52,4 +51,4 @@ async function main() {
await runQueryReadingResultsFromStream(query);
}

main();
main().catch((err) => console.error(err));

0 comments on commit ec00a1d

Please sign in to comment.