@incdevco/framework
Version:
node.js lambda framework
121 lines (60 loc) • 1.59 kB
JavaScript
module.exports = class UpdateExpression {
constructor() {
this._add = [];
this._delete = [];
this._remove = [];
this._set = [];
}
add(action) {
this._add.push(action);
}
delete(action) {
this._delete.push(action);
}
remove(action) {
this._remove.push(action);
}
render() {
let str = '';
if (this._set.length) {
str += 'SET ';
this._set.forEach((action, index) => {
if (index > 0) {
str += ', ';
}
str += action;
});
}
if (this._remove.length) {
str += 'REMOVE ';
this._remove.forEach((action, index) => {
if (index > 0) {
str += ', ';
}
str += action;
});
}
if (this._add.length) {
str += 'ADD ';
this._add.forEach((action, index) => {
if (index > 0) {
str += ', ';
}
str += action;
});
}
if (this._delete.length) {
str += 'DELETE ';
this._delete.forEach((action, index) => {
if (index > 0) {
str += ', ';
}
str += action;
});
}
return str;
}
set(action) {
this._set.push(action);
}
};