@easyquery/core
Version:
EasyQuery.JS core modules
98 lines • 3.19 kB
JavaScript
import { DataKind } from '../types/data_kind';
import { DataType } from '../types/data_type';
import { ExprTag } from '../types/expr_tag';
import { Query } from '../query/query';
var Expression = /** @class */ (function () {
function Expression() {
this.id = null;
this.tag = ExprTag.Constant;
this.kind = DataKind.Scalar;
this.dataType = DataType.String;
//DO NOT forget remove any
this.value = '';
this.text = '';
this.distinct = false;
this.args = new Array();
}
Expression.prototype.loadFromData = function (model, data) {
if (data) {
this.id = data.id;
this.tag = data.tag;
//Do not save other info for EntityAttr
if (this.tag == ExprTag.EntityAttribute
|| this.tag == ExprTag.ParentEntityAttribute) {
return;
}
this.kind = data.kind;
this.dataType = data.dtype;
if (data.query) {
this.query = new Query(model);
this.query.setData(data.query);
}
if (data.val) {
this.value = data.val;
this.text = data.txt;
}
if (typeof data.distinct !== 'undefined') {
this.distinct = data.distinct;
}
if (data.func) {
this.func = data.func;
if (data.args) {
for (var i = 0; i < data.args.length; i++) {
var arg = new Expression();
arg.loadFromData(model, data.args[i]);
this.args.push(arg);
}
}
}
if (data.sql) {
this.sql = data.sql;
this.baseAttrId = data.baseAttrId;
}
}
};
Expression.prototype.saveToData = function () {
var obj = {
id: this.id,
tag: this.tag
};
//Do not save other info for EntityAttr
if (this.tag == ExprTag.EntityAttribute) {
return obj;
}
if (this.query) {
obj.query = this.query.toJSONData();
}
if (typeof this.kind !== "undefined") {
obj.kind = this.kind;
}
if (typeof this.dataType !== "undefined") {
obj.dtype = this.dataType;
}
if (this.value) {
obj.val = this.value;
}
if (this.text) {
obj.txt = this.text;
}
if (this.distinct) {
obj.distinct = this.distinct;
}
if (this.func) {
obj.func = this.func;
obj.args = [];
for (var i = 0; i < this.args.length; i++) {
obj.args.push(this.args[i].saveToData());
}
}
if (this.sql) {
obj.sql = this.sql;
obj.baseAttrId = this.baseAttrId;
}
return obj;
};
return Expression;
}());
export { Expression };
//# sourceMappingURL=expression.js.map