alasql 4.8.0 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/alasql-cli.js CHANGED
@@ -10,7 +10,6 @@
10
10
  let alasql = require('../dist/alasql.fs.js');
11
11
  let path = require('path');
12
12
  let fs = require('fs');
13
- let stdin = process.openStdin();
14
13
  let yargs = require('yargs')
15
14
  .strict()
16
15
  .usage(
@@ -58,44 +57,73 @@ let yargs = require('yargs')
58
57
  .epilog('\nMore information about the library: www.alasql.org');
59
58
 
60
59
  let argv = yargs.argv;
61
- let sql = '';
62
- let params = [];
63
- let pipedData = '';
64
- stdin.on('data', function (chunk) {
65
- pipedData += chunk;
66
- });
67
60
 
68
- if (argv.v) {
69
- console.log(alasql.version);
70
- process.exit(0);
61
+ // Regex patterns for detecting functions
62
+ const re = {
63
+ txt: /txt\s*\(\s*\)/i,
64
+ };
65
+
66
+ // Helper function to check if SQL contains txt() and stdin is piped
67
+ function isPipeData(sql) {
68
+ return sql && !process.stdin.isTTY && re.txt.test(sql);
71
69
  }
72
70
 
73
- if (argv.f) {
74
- if (!fs.existsSync(argv.f)) {
71
+ // Helper function to setup stdin handling
72
+ function pipeIsSQL() {
73
+ const stdin = process.openStdin();
74
+ let pipedData = '';
75
+ stdin.on('data', function (chunk) {
76
+ pipedData += chunk;
77
+ });
78
+ stdin.on('end', function () {
79
+ execute(pipedData, argv._);
80
+ });
81
+ return stdin;
82
+ }
83
+
84
+ // Helper function to load and validate SQL file
85
+ function loadSqlFile(filePath) {
86
+ if (!fs.existsSync(filePath)) {
75
87
  console.error('Error: file not found');
76
88
  process.exit(1);
77
89
  }
78
-
79
- if (isDirectory(argv.f)) {
90
+ if (isDirectory(filePath)) {
80
91
  console.error('Error: file expected but directory found');
81
92
  process.exit(1);
82
93
  }
94
+ return fs.readFileSync(filePath, 'utf8').toString();
95
+ }
96
+
97
+ // Main execution logic
98
+ function main() {
99
+ let sql = '';
100
+ let pipeIsData = false;
101
+
102
+ if (argv.f) {
103
+ sql = loadSqlFile(argv.f);
104
+ pipeIsData = isPipeData(sql);
105
+ } else {
106
+ sql = argv._.shift() || '';
107
+ pipeIsData = isPipeData(sql);
108
+ }
83
109
 
84
- sql = fs.readFileSync(argv.f, 'utf8').toString();
85
- execute(sql, argv._);
86
- } else {
87
- sql = argv._.shift() || '';
110
+ // Setup stdin handling only if not using txt() pipe
111
+ if (!pipeIsData) {
112
+ pipeIsSQL();
113
+ }
88
114
 
89
- // if data is not piped
90
- if (Boolean(process.stdin.isTTY)) {
115
+ // Execute immediately if we have SQL or are using txt() pipe
116
+ if (sql || pipeIsData) {
91
117
  execute(sql, argv._);
92
118
  }
93
119
  }
94
120
 
95
- // if data is piped
96
- stdin.on('end', function () {
97
- execute(pipedData, argv._);
98
- });
121
+ if (argv.v) {
122
+ console.log(alasql.version);
123
+ process.exit(0);
124
+ }
125
+
126
+ main();
99
127
 
100
128
  /**
101
129
  * Execute SQL query
@@ -1,7 +1,7 @@
1
- //! AlaSQL v4.7.0 build: develop-916ff64e | © 2014-2024 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v4.8.0 build: develop-af967432 | © 2014-2024 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 4.7.0
4
+ @version 4.8.0
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2024 Andrey Gershun & Mathias Wulff
package/dist/alasql.fs.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v4.7.0 build: develop-916ff64e | © 2014-2024 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v4.8.0 build: develop-af967432 | © 2014-2024 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 4.7.0
4
+ @version 4.8.0
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2024 Andrey Gershun & Mathias Wulff
@@ -141,8 +141,8 @@ SOFTWARE.
141
141
  Current version of alasql
142
142
  @constant {string}
143
143
  */
144
- alasql.version = '4.7.0';
145
- alasql.build = 'develop-916ff64e';
144
+ alasql.version = '4.8.0';
145
+ alasql.build = 'develop-af967432';
146
146
 
147
147
  /**
148
148
  Debug flag
@@ -3487,7 +3487,7 @@ let loadFile = (utils.loadFile = function (path, asy, success, error) {
3487
3487
  fs = require('fs');
3488
3488
 
3489
3489
  // If path is empty, than read data from stdin (for Node)
3490
- if (typeof path === 'undefined') {
3490
+ if ([null, undefined].includes(path)) {
3491
3491
  var buff = '';
3492
3492
  process.stdin.setEncoding('utf8');
3493
3493
  process.stdin.on('readable', function () {
package/dist/alasql.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v4.7.0 build: develop-916ff64e | © 2014-2024 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v4.8.0 build: develop-af967432 | © 2014-2024 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 4.7.0
4
+ @version 4.8.0
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2024 Andrey Gershun & Mathias Wulff
@@ -141,8 +141,8 @@ SOFTWARE.
141
141
  Current version of alasql
142
142
  @constant {string}
143
143
  */
144
- alasql.version = '4.7.0';
145
- alasql.build = 'develop-916ff64e';
144
+ alasql.version = '4.8.0';
145
+ alasql.build = 'develop-af967432';
146
146
 
147
147
  /**
148
148
  Debug flag
@@ -3487,7 +3487,7 @@ let loadFile = (utils.loadFile = function (path, asy, success, error) {
3487
3487
  fs = require('fs');
3488
3488
 
3489
3489
  // If path is empty, than read data from stdin (for Node)
3490
- if (typeof path === 'undefined') {
3490
+ if ([null, undefined].includes(path)) {
3491
3491
  var buff = '';
3492
3492
  process.stdin.setEncoding('utf8');
3493
3493
  process.stdin.on('readable', function () {