| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- "use strict";
- /**
- * Internal expression for constant values
- * @class ConstantExpression
- * @namespace mungedb-aggregate.pipeline.expressions
- * @module mungedb-aggregate
- * @constructor
- **/
- var ConstantExpression = module.exports = function ConstantExpression(value){
- if (arguments.length !== 1) throw new Error("args expected: value");
- this.value = value; //TODO: actually make read-only in terms of JS?
- base.call(this);
- }, klass = ConstantExpression, base = require("./Expression"), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
- // DEPENDENCIES
- var Value = require("../Value"),
- Expression = require("./Expression");
- // PROTOTYPE MEMBERS
- proto.getOpName = function getOpName(){
- return "$const";
- };
- /**
- * Get the constant value represented by this Expression.
- * @method getValue
- * @returns the value
- **/
- proto.getValue = function getValue(){ //TODO: convert this to an instance field rather than a property
- return this.value;
- };
- proto.addDependencies = function addDependencies(deps, path) {
- // nothing to do
- };
- klass.parse = function parse(expr, vps){
- return new ConstantExpression(expr);
- };
- /**
- * Get the constant value represented by this Expression.
- * @method evaluate
- **/
- proto.evaluateInternal = function evaluateInternal(vars){
- return this.value;
- };
- proto.optimize = function optimize() {
- return this; // nothing to do
- };
- proto.serialize = function(rawValue){
- return rawValue ? {$const: this.value} : this.value;
- };
- //TODO: proto.addToBsonObj --- may be required for $project to work -- my hope is that we can implement toJSON methods all around and use that instead
- //TODO: proto.addToBsonArray
- /** Register Expression */
- Expression.registerExpression("$const",klass.parse(ConstantExpression));
- Expression.registerExpression("$literal", klass.parse(ConstantExpression)); // alias
|