Skip to content

Commit

Permalink
format logical expression in case when expression (#33)
Browse files Browse the repository at this point in the history
* format logical expression in case when

* 2.7.1
  • Loading branch information
kbarbounakis authored Jun 7, 2023
1 parent 0d99a21 commit b102d8a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@themost/mssql",
"version": "2.7.0",
"version": "2.7.1",
"description": "MOST Web Framework MSSQL Data Adapter",
"main": "dist/index.js",
"module": "dist/index.esm.js",
Expand Down
9 changes: 8 additions & 1 deletion src/MSSqlFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,19 @@ class MSSqlFormatter extends SqlFormatter {
return sprintf('CAST(%s AS NVARCHAR)', this.escape(p0));
}

isLogical = function(obj) {
for (const key in obj) {
return (/^\$(and|or|not|nor)$/g.test(key));
}
return false;
}

$cond(ifExpr, thenExpr, elseExpr) {
// validate ifExpr which should an instance of QueryExpression or a comparison expression
let ifExpression;
if (ifExpr instanceof QueryExpression) {
ifExpression = this.formatWhere(ifExpr.$where);
} else if (this.isComparison(ifExpr)) {
} else if (this.isComparison(ifExpr) || this.isLogical(ifExpr)) {
ifExpression = this.formatWhere(ifExpr);
} else {
throw new Error('Condition parameter should be an instance of query or comparison expression');
Expand Down

0 comments on commit b102d8a

Please sign in to comment.