Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/usr/bin/env node
//
// Alacon - Command line interface for Alasql
// Version: 0.1
// Date: 07.04.2015
// (c) 2014-2015, Andrey Gershun
//
var alasql = require('alasql');
var fs = require('fs');
if(process.argv.length <= 2) {
console.log('alacon - Alasql command-line utility (version '+alasql.version+') ');
console.log();
console.log('Usage:');
console.log(' node alacon "sql-statement" [ param0 ]... - run SQL statement');
console.log(' node alacon -f file.sql [ param0 ]... - run SQL from file');
console.log();
console.log('Samples:');
console.log(' node alacon \'select 2+2\'');
console.log(' node alacon \'select count(*) from txt()\' 2) {
var sql = process.argv[2];
var parami = 3;
if(sql == '-f') {
console.log(sql);
sql = fs.readFile(sql).toString();
#!/usr/bin/env node
//
// Command line interface for Alasql
// Version: 0.2.2
// Date: 28.07.2015
// (c) 2014-2015, Andrey Gershun & M. Rangel Wulff
//
var alasql = require('alasql');
var path = require('path');
var fs = require('fs');
var yargs = require('yargs')
.demand(1)
.strict()
.usage('AlaSQL command-line utility (version '+alasql.version+')\n\nUsage: $0 [options] [sql] [params]')
.example('$0 "sql-statement"', 'Run SQL statement and output result as JSON')
.example('')
.example('$0 \'value of select 2+?\' 40', 'Outputs 42')
.example('')
.example('$0 \'select count(*) from txt()\' < city.txt', 'Count lines in city.txt')
.example('')
.example('$0 \'select * into xlsx("city.xlsx") from txt("city.txt")\'', 'Convert from txt to xlsx')
.example('')
.example('$0 --file file.sql France 1960', 'Run SQL from file with 2 parameters')
.version('v', 'Echo AlaSQL version', alasql.version)
.alias('v', 'version')
.boolean('m')
.describe('m', 'Minify json output')
.describe('f', 'Load SQL from file')
.alias('f', 'file')
.nargs('f', 1)
.normalize('f')
.help('h')
.alias('h', 'help')
.epilog('\nMore information about the library: www.alasql.org')
var argv = yargs.argv;
var sql = '';
var params = [];
if(argv.v) {
console.log(alasql.version);
process.exit(0);
}
if(argv.f) {
if (!fs.existsSync(argv.f)) {
console.log('Error: file not found');
process.exit(1);
}
if (isDirectory(argv.f)) {
console.log('Error: file expected but directory found');
process.exit(1);
}
sql = fs.readFileSync(argv.f, 'utf8').toString();
} else {