public QueryJoin(string modelField, IModel joinedModel, string joinedField, JoinType joinType, QExprGroup joinConditions) { ModelField = modelField; JoinedModel = joinedModel; JoinedField = joinedField; Type = joinType; JoinConditions = joinConditions; }
internal static QExprGroup CreateExprGroup(string groupOperator, CallInfo callInfo, object[] args) { if(callInfo != null && args != null && args.Length > 0 && callInfo.ArgumentCount == args.Length) { int argsCount = args.Length; int namedArgsCount = callInfo.ArgumentNames.Count; QExpr[] qexprs = new QExpr[namedArgsCount]; QExprGroup[] qgroups = new QExprGroup[argsCount - namedArgsCount]; for (int i = 0; i < argsCount - namedArgsCount; i++) { QExprGroup qgroup = args[i] as QExprGroup; if (qgroup == null) throw new Exception("An unnamed Q parameter must be of type QPredicate"); qgroups[i] = qgroup; } for (int i = 0; i < namedArgsCount; i++) { string[] lhsAndOp = callInfo.ArgumentNames[i].Split(CUSTOM_QUERY_SYNTAX_SEP, StringSplitOptions.None); if (lhsAndOp == null || lhsAndOp.Length == 0 || lhsAndOp.Length < 1) throw new Exception("A Q parameter name must be composed of field name & operator name separated by '__' (double underscore)"); qexprs[i] = new QExpr(lhsAndOp[0], lhsAndOp.Length >= 2 ? lhsAndOp[lhsAndOp.Length - 1] : Constants.QueryCompareOps.EXACT, args[argsCount - namedArgsCount + i]); } QExprGroup exprGroup; if (groupOperator == Constants.QUERY_AND) exprGroup = new AndExprGroup(); else exprGroup = new OrExprGroup(); if (qgroups != null) exprGroup.SubGroups.AddRange(qgroups); if (qexprs != null) exprGroup.Expressions.AddRange(qexprs); return exprGroup; } return null; }
internal void Compile() { if (!_compiled) { WhereExpressions = CombineAll(); int lastIndex = WhereExpressions.Compile(1); foreach (QueryJoin join in _joins) lastIndex = join.JoinConditions.Compile(lastIndex); _compiled = true; } }
public Queryset Filter(QExprGroup filterConditions) { ExceptionIfCompiled(); _filterConditions = QExprGroup.Combine(_filterConditions, filterConditions); return this; }
public Queryset Join(string modelField, IModel joinedModel, string joinedField, QueryJoin.JoinType joinType, QExprGroup joinConditions) { _joins.Add(new QueryJoin(modelField, joinedModel, joinedField, joinType, joinConditions)); return this; }
public Queryset Exclude(QExprGroup excludeConditions) { ExceptionIfCompiled(); _excludeConditions = QExprGroup.Combine(_excludeConditions, excludeConditions); return this; }
public QExprGroup Add(QExprGroup subGroup) { SubGroups.Add(subGroup); return this; }
public static QExprGroup Combine(QExprGroup subGroup1, QExprGroup subGroup2, string groupOperator = Constants.QUERY_AND) { QExprGroup group; if (groupOperator == Constants.QUERY_AND) group = new AndExprGroup(); else group = new OrExprGroup(); if (subGroup1 != null) group.SubGroups.Add(subGroup1); if (subGroup2 != null) group.SubGroups.Add(subGroup2); return group; }
public Queryset Filter(QExprGroup filterConditions) { return CreateQuerySet().Filter(filterConditions); }
public Queryset Exclude(QExprGroup excludeConditions) { return CreateQuerySet().Exclude(excludeConditions); }