Skip to content

Commit 28af406

Browse files
committed
Simplify conditions
1 parent 92221c1 commit 28af406

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/sql.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ function tablesToSQL(tables) {
163163
if (baseTable.type === 'dual') return 'DUAL';
164164
let str = baseTable.table ? identifierToSql(baseTable.table) : exprToSQL(baseTable.expr);
165165

166-
if (baseTable.db && baseTable.db !== null) str = baseTable.db + '.' + str;
166+
if (baseTable.db) str = baseTable.db + '.' + str;
167167
if (baseTable.as !== null) str += ' AS ' + identifierToSql(baseTable.as);
168168

169169
clauses.push(str);
170170

171171
for (let i = 1; i < tables.length; i++) {
172172
const joinExpr = tables[i];
173173

174-
str = joinExpr.join && joinExpr.join !== null ? ' ' + joinExpr.join + ' ' : (str = ', ');
174+
str = joinExpr.join ? ' ' + joinExpr.join + ' ' : (str = ', ');
175175

176176
if (joinExpr.table) {
177177
if (joinExpr.db !== null) str += joinExpr.db + '.';
@@ -212,7 +212,7 @@ function withToSql(withExpr) {
212212
* @param {Object} stmt
213213
* @param {?Array} stmt.with
214214
* @param {?Array} stmt.options
215-
* @param {?string} stmt.distinct
215+
* @param {string|null} stmt.distinct
216216
* @param {?Array|string} stmt.columns
217217
* @param {?Array} stmt.from
218218
* @param {?Object} stmt.where
@@ -229,8 +229,7 @@ function selectToSQL(stmt) {
229229
if (has(stmt, 'options') && Array.isArray(stmt.options)) clauses.push(stmt.options.join(' '));
230230
if (has(stmt, 'distinct') && stmt.distinct !== null) clauses.push(stmt.distinct);
231231

232-
if (stmt.columns !== '*') clauses.push(columnsToSQL(stmt.columns));
233-
else clauses.push('*');
232+
clauses.push(stmt.columns !== '*' ? columnsToSQL(stmt.columns) : '*');
234233

235234
// FROM + joins
236235
if (Array.isArray(stmt.from)) clauses.push('FROM', tablesToSQL(stmt.from));

0 commit comments

Comments
 (0)