UNPKG

plywood

Version:
79 lines (78 loc) 3.04 kB
import { __extends } from "tslib"; import { SqlExpression, SqlFunction } from 'druid-query-toolkit'; import { Expression } from './baseExpression'; var SqlRefExpression = (function (_super) { __extends(SqlRefExpression, _super); function SqlRefExpression(parameters) { var _this = _super.call(this, parameters, dummyObject) || this; _this._ensureOp('sqlRef'); var sql = parameters.sql; if (typeof sql !== 'string' || sql.length === 0) { throw new TypeError('must have a nonempty `sql`'); } _this.sql = sql; _this.type = parameters.type; _this.simple = true; _this.parsedSql = SqlExpression.parse(_this.sql); return _this; } SqlRefExpression.fromJS = function (parameters) { var value = Expression.jsToValue(parameters); value.sql = parameters.sql; return new SqlRefExpression(value); }; SqlRefExpression.prototype.valueOf = function () { var value = _super.prototype.valueOf.call(this); value.sql = this.sql; return value; }; SqlRefExpression.prototype.toJS = function () { var js = _super.prototype.toJS.call(this); js.sql = this.sql; js.type = this.type; return js; }; SqlRefExpression.prototype.toString = function () { var _a = this, sql = _a.sql, type = _a.type; return type ? "s${".concat(sql, "}:").concat(type) : "s${".concat(sql, "}"); }; SqlRefExpression.prototype.changeSql = function (sql) { var value = this.valueOf(); value.sql = sql; return new SqlRefExpression(value); }; SqlRefExpression.prototype.getFn = function () { throw new Error('can not getFn on SQL'); }; SqlRefExpression.prototype.calc = function (_datum) { throw new Error('can not calc on SQL'); }; SqlRefExpression.prototype.getSQL = function (dialect, _minimal) { if (_minimal === void 0) { _minimal = false; } if (this.type) { try { return dialect.castExpression(undefined, this.sql, this.type); } catch (_a) { } } return "(".concat(this.sql, ")"); }; SqlRefExpression.prototype.equals = function (other) { return _super.prototype.equals.call(this, other) && this.sql === other.sql; }; SqlRefExpression.prototype.isSqlFunction = function () { var functionNames = []; for (var _i = 0; _i < arguments.length; _i++) { functionNames[_i] = arguments[_i]; } var upperCaseFunctionNames = functionNames.map(function (functionName) { return functionName.toUpperCase(); }); var parsedSql = this.parsedSql; return (parsedSql instanceof SqlFunction && upperCaseFunctionNames.includes(parsedSql.getEffectiveFunctionName())); }; SqlRefExpression.op = 'SqlRef'; return SqlRefExpression; }(Expression)); export { SqlRefExpression }; Expression.register(SqlRefExpression);