UNPKG

@uwdata/mosaic-sql

Version:

SQL query construction and analysis.

58 lines (51 loc) 1.35 kB
import { UNARY_OPERATOR, UNARY_POSTFIX_OPERATOR } from '../constants.js'; import { ExprNode } from './node.js'; class AbstractUnaryOpNode extends ExprNode { /** The operator type. */ readonly op: string; /** The input expression. */ readonly expr: ExprNode; /** * Instantiate an abstract unary operator node. * @param type The node type. * @param op The operator type. * @param expr The input expression. */ constructor(type: string, op: string, expr: ExprNode) { super(type); this.op = op; this.expr = expr; } } export class UnaryOpNode extends AbstractUnaryOpNode { /** * Instantiate a unary operator node. * @param op The operator type. * @param expr The input expression. */ constructor(op: string, expr: ExprNode) { super(UNARY_OPERATOR, op, expr); } /** * Generate a SQL query string for this node. */ toString() { return `(${this.op} ${this.expr})`; } } export class UnaryPostfixOpNode extends AbstractUnaryOpNode { /** * Instantiate a unary operator node. * @param op The operator type. * @param expr The input expression. */ constructor(op: string, expr: ExprNode) { super(UNARY_POSTFIX_OPERATOR, op, expr); } /** * Generate a SQL query string for this node. */ toString() { return `(${this.expr} ${this.op})`; } }