Skip to content

Commit 6d2de7a

Browse files
committed
operand count added
1 parent fff090e commit 6d2de7a

4 files changed

Lines changed: 22 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ sql.matchTsquery('columns', ['total', 'fat']);
3535
| [selectTsquery] | Generates SQL command for SELECT with tsquery.
3636
| [matchTsquery] | Generates SQL query for matching words with tsquery.
3737
| [OPERATORS] | Set of operators in SQL. {field}
38+
| [OPERAND_COUNT] | Number of operands used with an SQL operator. {field}
3839

3940
<br>
4041
<br>
@@ -49,4 +50,6 @@ sql.matchTsquery('columns', ['total', 'fat']);
4950
[tableExists]: https://github.com/nodef/extra-sql/wiki/tableExists
5051
[selectTsquery]: https://github.com/nodef/extra-sql/wiki/selectTsquery
5152
[matchTsquery]: https://github.com/nodef/extra-sql/wiki/matchTsquery
53+
[OPERATORS]: https://github.com/nodef/extra-sql/wiki/OPERATORS
54+
[OPERAND_COUNT]: https://github.com/nodef/extra-sql/wiki/OPERAND_COUNT
5255
[SQL]: https://en.wikipedia.org/wiki/SQL

index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ const OPERATORS = new Set([
1414
'ALL', 'AND', 'ANY', 'BETWEEN', 'EXISTS', 'IN', 'IN', 'LIKE', 'NOT', 'OR', 'SOME'
1515
]);
1616

17+
/**
18+
* Number of operands used with an SQL operator.
19+
*/
20+
const OPERAND_COUNT = new Map([
21+
// arithmetic operators
22+
['+', 2], ['-', 2], ['*', 2], ['/', 2], ['%', 2],
23+
// bitwise operators
24+
['&', 2], ['|', 2], ['^', 2],
25+
// comparision operators
26+
['=', 2], ['>', 2], ['<', 2], ['>=', 2], ['<=', 2], ['<>', 2],
27+
// compound operators
28+
['+=', 2], ['-=', 2], ['*=', 2], ['/=', 2], ['%=', 2], ['&=', 2], ['^=', 2], ['|=', 2],
29+
// logical operators
30+
['ALL', 2], ['AND', 2], ['ANY', 2], ['BETWEEN', 3], ['EXISTS', 1], ['IN', 2], ['LIKE', 2], ['NOT', 1], ['OR', 2], ['SOME', 2]
31+
]);
32+
1733

1834
/**
1935
* Generates SQL command for CREATE TABLE.
@@ -220,6 +236,7 @@ function matchTsquery(tab, wrds, tsv='"tsvector"', opt={}) {
220236
return z;
221237
}
222238
exports.OPERATORS = OPERATORS;
239+
exports.OPERAND_COUNT = OPERAND_COUNT;
223240
exports.createTable = createTable;
224241
exports.createIndex = createIndex;
225242
exports.createView = createView;

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "extra-sql",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "SQL is designed for managing or stream processing data in an RDBMS.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)