@uwdata/mosaic-sql
Version:
SQL query construction and analysis.
36 lines • 1.37 kB
JavaScript
import { WITH_CLAUSE } from '../constants.js';
import { SQLNode } from './node.js';
export class WithClauseNode extends SQLNode {
/** The common table expression (CTE) name. */
name;
/** The common table expression (CTE) query. */
query;
/** The common table expression (CTE) materialization flag. */
materialized;
/**
* Instantiate a with clause node for a common table expression (CTE).
* @param name The common table expression (CTE) name.
* @param query The common table expression (CTE) query.
* @param materialized The common table expression (CTE)
* materialization flag. If `true`, forces materialization of the CTE.
* If `false`, materialization is not performed. Otherwise (for example, if
* `undefined` or `null`), materialization is decided by the database.
*/
constructor(name, query, materialized = null) {
super(WITH_CLAUSE);
this.name = name;
this.query = query;
this.materialized = materialized;
}
/**
* Generate a SQL query string for this node.
*/
toString() {
const flag = this.materialized;
const mat = flag === true ? ' MATERIALIZED'
: flag === false ? ' NOT MATERIALIZED'
: '';
return `"${this.name}" AS${mat} (${this.query})`;
}
}
//# sourceMappingURL=with.js.map