UNPKG

@uwdata/mosaic-sql

Version:

SQL query construction and analysis.

58 lines 1.49 kB
import { COLUMN_REF } from '../constants.js'; import { quoteIdentifier } from '../util/string.js'; import { ExprNode } from './node.js'; /** * Check if a value is a column reference node. * @param value The value to check. */ export function isColumnRef(value) { return value instanceof ColumnRefNode; } export class ColumnRefNode extends ExprNode { /** The table reference. */ table; /** * Instantiate a column reference node. * @param type The AST node type. * @param table The table reference. */ constructor(type, table) { super(type); this.table = table; } /** * Returns the column name. */ get column() { return ''; // subclasses to override } /** * Generate a SQL query string for this node. */ toString() { const { column, table } = this; const tref = `${table ?? ''}`; const id = column === '*' ? '*' : quoteIdentifier(column); return (tref ? (tref + '.') : '') + id; } } export class ColumnNameRefNode extends ColumnRefNode { /** The column name. */ name; /** * Instantiate a column reference node. * @param name The column name. * @param table The table reference. */ constructor(name, table) { super(COLUMN_REF, table); this.name = name; } /** * Returns the column name. */ get column() { return this.name; } } //# sourceMappingURL=column-ref.js.map