public void VisitUpsertAndReturnClause(UpsertAndReturnClause upsertAndReturnClause, QueryModel queryModel) { QueryText.Append(" upsert "); GetAqlExpression(upsertAndReturnClause.SearchSelector, queryModel); QueryText.Append(" insert "); GetAqlExpression(upsertAndReturnClause.InsertSelector, queryModel); QueryText.Append(" update "); GetAqlExpression(upsertAndReturnClause.UpdateSelector, queryModel); CrudState.ModelVisitorHaveCrudOperation = true; CrudState.Collection = LinqUtility.ResolveCollectionName(Db, upsertAndReturnClause.CollectionType); CrudState.ReturnResult = upsertAndReturnClause.ReturnResult; CrudState.ReturnResultKind = "NEW"; }
public void VisitRemoveAndReturnClause(RemoveAndReturnClause removeAndReturnClause, QueryModel queryModel) { if (removeAndReturnClause.KeySelector != null) { QueryText.Append(" remove "); GetAqlExpression(removeAndReturnClause.KeySelector, queryModel); } else { QueryText.AppendFormat(" remove {0} ", LinqUtility.ResolvePropertyName(removeAndReturnClause.ItemName)); } CrudState.ModelVisitorHaveCrudOperation = true; CrudState.Collection = LinqUtility.ResolveCollectionName(Db, removeAndReturnClause.CollectionType); CrudState.ReturnResult = removeAndReturnClause.ReturnResult; CrudState.ReturnResultKind = "OLD"; }
public void VisitInsertAndReturnClause(InsertAndReturnClause insertAndReturnClause, QueryModel queryModel) { if (insertAndReturnClause.WithSelector != null) { QueryText.Append(" insert "); GetAqlExpression(insertAndReturnClause.WithSelector, queryModel); } else { QueryText.AppendFormat(" insert {0} ", LinqUtility.ResolvePropertyName(insertAndReturnClause.ItemName)); } CrudState.ModelVisitorHaveCrudOperation = true; CrudState.Collection = LinqUtility.ResolveCollectionName(Db, insertAndReturnClause.CollectionType); CrudState.ReturnResult = insertAndReturnClause.ReturnResult; CrudState.ReturnResultKind = "NEW"; }
public override void VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel) { if (fromClause.FromExpression as SubQueryExpression != null) { throw new Exception("MainFromClause.FromExpression cant be SubQueryExpression because group by is handle in itself clause"); } string fromName = LinqUtility.ResolveCollectionName(this.Db, fromClause.ItemType); if (fromClause.FromExpression.Type.Name == "IGrouping`2") { var groupByClause = LinqUtility.PriorGroupBy(ParnetModelVisitor); var parentMVisitor = LinqUtility.FindParentModelVisitor(this); //parentMVisitor.GroupByNameCounter++; fromName = groupByClause[0].TranslateIntoName(); fromName = LinqUtility.ResolvePropertyName(fromName); } if (fromClause.FromExpression.NodeType == ExpressionType.Constant || fromClause.FromExpression.Type.Name == "IGrouping`2") { if (fromClause.FromExpression.Type.Name == "AqlQueryable`1" || fromClause.FromExpression.Type.Name == "IGrouping`2") { QueryText.AppendFormat(" for {0} in {1} ", LinqUtility.ResolvePropertyName(fromClause.ItemName), fromName); } else { QueryText.AppendFormat(" for {0} in ", LinqUtility.ResolvePropertyName(fromClause.ItemName)); GetAqlExpression(fromClause.FromExpression, queryModel); } } else { QueryText.AppendFormat(" for {0} in ", LinqUtility.ResolvePropertyName(fromClause.ItemName)); GetAqlExpression(fromClause.FromExpression, queryModel); } base.VisitMainFromClause(fromClause, queryModel); }
public override void VisitAdditionalFromClause(AdditionalFromClause fromClause, QueryModel queryModel, int index) { var subQuery = fromClause.FromExpression as SubQueryExpression; if (subQuery != null) { this.DontReturn = true; GetAqlExpression(subQuery, queryModel, handleJoin: true); } else if (fromClause.FromExpression.Type.Name == "AqlQueryable`1") { string fromName = LinqUtility.ResolveCollectionName(this.Db, fromClause.ItemType); QueryText.AppendFormat(" for {0} in {1} ", LinqUtility.ResolvePropertyName(fromClause.ItemName), fromName); } else { QueryText.AppendFormat(" for {0} in ", LinqUtility.ResolvePropertyName(fromClause.ItemName)); GetAqlExpression(fromClause.FromExpression, queryModel); } }
public void VisitUpdateAndReturnClause(UpdateAndReturnClause updateAndReturnClause, QueryModel queryModel) { if (updateAndReturnClause.KeySelector != null) { QueryText.AppendFormat(" {0} ", updateAndReturnClause.Command); GetAqlExpression(updateAndReturnClause.KeySelector, queryModel); QueryText.AppendFormat(" with "); } else { QueryText.AppendFormat(" {0} {1} with ", updateAndReturnClause.Command, LinqUtility.ResolvePropertyName(updateAndReturnClause.ItemName)); } GetAqlExpression(updateAndReturnClause.WithSelector, queryModel); CrudState.ModelVisitorHaveCrudOperation = true; CrudState.Collection = LinqUtility.ResolveCollectionName(Db, updateAndReturnClause.CollectionType); CrudState.ReturnResult = updateAndReturnClause.ReturnResult; CrudState.ReturnResultKind = updateAndReturnClause.ReturnNewResult ? "NEW" : "OLD"; }
protected override Expression VisitMethodCallExpression(MethodCallExpression expression) { if (expression.Method.Name == "As") { VisitExpression(expression.Arguments[0]); return(expression); } string methodName; var userFunction = ModelVisitor.Db.SharedSetting.AqlFunctions.FindFunctionAttribute(expression.Method); bool methodExists = userFunction != null; if (methodExists) { methodName = userFunction.Name; } else { methodExists = aqlMethods.TryGetValue(expression.Method.Name, out methodName); } if (!methodExists) { throw new InvalidOperationException($"Method {expression.Method.Name} is not supported in AqlLinqProvider"); } string argumentSeprator = null; bool noParenthesis = methodsWithNoParenthesis.TryGetValue(methodName, out argumentSeprator); if (!noParenthesis) { ModelVisitor.QueryText.AppendFormat(" {0}( ", methodName); argumentSeprator = " , "; } Type[] genericArguments = null; if (methodsWithFirstGenericArgument.Contains(methodName)) { genericArguments = expression.Method.GetGenericArguments(); var collection = LinqUtility.ResolveCollectionName(ModelVisitor.Db, genericArguments[0]); ModelVisitor.QueryText.AppendFormat(" {0}{1}", collection, argumentSeprator); } if (methodsWithSecondGenericArgument.Contains(methodName)) { var collection = LinqUtility.ResolveCollectionName(ModelVisitor.Db, genericArguments[1]); ModelVisitor.QueryText.AppendFormat(" {0}{1}", collection, argumentSeprator); } for (int i = 0; i < expression.Arguments.Count; i++) { VisitExpression(expression.Arguments[i]); if (i != expression.Arguments.Count - 1) { ModelVisitor.QueryText.Append(argumentSeprator); } } if (!noParenthesis) { ModelVisitor.QueryText.Append(" ) "); } return(expression); }