UNPKG

@uwdata/mosaic-sql

Version:

SQL query construction and analysis.

35 lines 1.01 kB
import { SELECT_CLAUSE } from '../constants.js'; import { quoteIdentifier } from '../util/string.js'; import { ColumnRefNode } from './column-ref.js'; import { SQLNode } from './node.js'; export class SelectClauseNode extends SQLNode { /** The select expression. */ expr; /** The output name. */ alias; /** * Instantiate a select node. * @param expr The select expression. * @param alias The output name. */ constructor(expr, alias) { super(SELECT_CLAUSE); this.expr = expr; this.alias = alias; } /** * Generate a SQL query string for this node. */ toString() { const { expr, alias } = this; return !alias || isColumnRefFor(expr, alias) ? `${expr}` : `${expr} AS ${quoteIdentifier(alias)}`; } } function isColumnRefFor(expr, name) { return expr instanceof ColumnRefNode && expr.table == null && expr.column === name; } //# sourceMappingURL=select.js.map