private RqlExpression VisitOperatorEq(RqlFunctionCallExpression node) { if (node.Arguments.Count != 2) { ThrowError(node, "Equality takes exactly two arguments"); } RqlIdentifierExpression identifier = node.Arguments[0] as RqlIdentifierExpression; if (identifier == null) { ThrowError(node.Arguments[0], "First argument must be a field identifier"); } RqlConstantExpression constant = node.Arguments[1] as RqlConstantExpression; if (constant == null) { ThrowError(node, "Second argument must be a constant"); } sb.Append("{"); VisitIdentifier(identifier); VisitConstant(constant); sb.Append("}"); return(node); }
private RqlExpression VisitOperatorSize(RqlFunctionCallExpression node) { if (node.Arguments.Count != 2) { ThrowError(node, "{0} takes exactly two arguments", node.Name); } RqlIdentifierExpression identifier = node.Arguments[0] as RqlIdentifierExpression; if (identifier == null) { ThrowError(node.Arguments[0], "First argument must be an identifier"); } RqlConstantExpression constant = node.Arguments[1] as RqlConstantExpression; if (constant == null || constant.Value.GetType() != typeof(int)) { ThrowError(node.Arguments[1], "Second argument must be an integer constant"); } sb.Append("{"); VisitIdentifier(identifier); sb.Append("{$"); sb.Append(node.Name); sb.Append(": "); VisitConstant(constant); sb.Append("}"); sb.Append("}"); return(node); }
private RqlExpression VisitOperatorLikeLikei(RqlFunctionCallExpression node) { if (node.Arguments.Count != 2) { ThrowError(node, "{0} takes exactly two arguments", node.Name); } RqlIdentifierExpression identifier = node.Arguments[0] as RqlIdentifierExpression; if (identifier == null) { ThrowError(node.Arguments[0], "First argument must be an identifier"); } RqlConstantExpression constant = node.Arguments[1] as RqlConstantExpression; if (constant == null || constant.Value.GetType() != typeof(string)) { ThrowError(node, "Second argument must be a string constant"); } bool ignoreCase = (identifier.Name == "likei"); sb.Append("{"); VisitIdentifier(identifier); sb.AppendFormat(@"/\b{0}/{1}", Regex.Escape((string)((RqlConstantExpression)node.Arguments[1]).Value), ignoreCase ? "i" : ""); sb.Append("}"); return(node); }
private RqlExpression VisitOperatorNeGtGteLtLte(RqlFunctionCallExpression node) { if (node.Arguments.Count != 2) { ThrowError(node, String.Format("{0} takes exactly two arguments", node.Name)); } RqlIdentifierExpression identifier = node.Arguments[0] as RqlIdentifierExpression; if (identifier == null) { ThrowError(node.Arguments[0], "First argument must be a field identifier"); } RqlConstantExpression constant = node.Arguments[1] as RqlConstantExpression; if (constant == null) { ThrowError(node, "Second argument must be a constant"); } sb.Append("{"); VisitIdentifier(identifier); sb.Append("{$"); sb.Append(node.Name); sb.Append(": "); VisitConstant(constant); sb.Append("}"); sb.Append("}"); return(node); }
protected override RqlExpression VisitConstant(RqlConstantExpression node) { s += FormatSimpleConstant(node.Type, node.Value); return(node); }
protected override RqlExpression VisitConstant(RqlConstantExpression node) { object nodeValue = node.Value; Type nodeType = node.Type; // Convert RQL types into primitive types if (nodeType == typeof(RqlId)) { nodeValue = ((RqlId)nodeValue).ToObjectId(); nodeType = nodeValue.GetType(); } else if (nodeType == typeof(RqlDateTime)) { nodeValue = (DateTime)(RqlDateTime)nodeValue; nodeType = nodeValue.GetType(); } else if (nodeType == typeof(RqlTimeSpan)) { nodeValue = (TimeSpan)(RqlTimeSpan)nodeValue; nodeType = nodeValue.GetType(); } // Now convert the primitive into the MongoDB type if (nodeValue == null) { sb.Append("null"); } else if (nodeType == typeof(string)) { sb.Append("\"" + nodeValue + "\""); } else if (nodeType == typeof(bool)) { sb.Append(nodeValue.ToString().ToLower()); } else if (nodeType == typeof(ObjectId)) { sb.Append("ObjectId(\""); sb.Append(((ObjectId)nodeValue).ToString()); sb.Append("\")"); } else if (nodeType == typeof(DateTime)) { sb.Append("ISODate(\""); sb.Append(((DateTime)nodeValue).ToString(RqlDateTime.FormatPattern)); sb.Append("\")"); } else if (nodeType == typeof(TimeSpan)) { sb.Append(((TimeSpan)nodeValue).TotalMilliseconds.ToString()); } else if (nodeType == typeof(double)) { sb.Append(nodeValue.ToString()); } else if (nodeType == typeof(int)) { sb.Append(nodeValue.ToString()); } else { throw new NotImplementedException(); } return(node); }