Exemplo n.º 1
0
 public OrderByField(string name, OrderByFieldType orderingType, bool ascending, MethodType?method = null, Argument[] arguments = null)
 {
     Method       = method;
     Name         = name;
     OrderingType = orderingType;
     Ascending    = ascending;
     Arguments    = arguments;
 }
Exemplo n.º 2
0
 public OrderByField(QueryFieldName name, OrderByFieldType orderingType, bool ascending, MethodType?method = null, Argument[] arguments = null)
 {
     Method               = method;
     Name                 = name;
     OrderingType         = orderingType;
     Ascending            = ascending;
     Arguments            = arguments;
     AggregationOperation = AggregationOperation.None;
 }
Exemplo n.º 3
0
        private List <(QueryExpression Expression, OrderByFieldType OrderingType, bool Ascending)> OrderBy()
        {
            var orderBy = new List <(QueryExpression Expression, OrderByFieldType OrderingType, bool Ascending)>();

            do
            {
                if (Field(out var field) == false)
                {
                    ThrowParseException("Unable to get field for ORDER BY");
                }

                OrderByFieldType type = OrderByFieldType.Implicit;

                QueryExpression op;
                if (Scanner.TryScan('('))
                {
                    if (Method(field, out op) == false)
                    {
                        ThrowParseException($"Unable to parse method call {QueryExpression.Extract(Scanner.Input, field)}for ORDER BY");
                    }
                }
                else
                {
                    op = new QueryExpression
                    {
                        Field = field,
                        Type  = OperatorType.Field
                    };
                }

                if (Scanner.TryScan("AS") && Scanner.TryScan(OrderByAsOptions, out var asMatch))
                {
                    switch (asMatch)
                    {
                    case "string":
                        type = OrderByFieldType.String;
                        break;

                    case "long":
                        type = OrderByFieldType.Long;
                        break;

                    case "double":
                        type = OrderByFieldType.Double;
                        break;

                    case "alphaNumeric":
                        type = OrderByFieldType.AlphaNumeric;
                        break;
                    }
                }

                var asc = true;

                if (Scanner.TryScan(OrderByOptions, out var match))
                {
                    if (match == "DESC" || match == "DESCENDING")
                    {
                        asc = false;
                    }
                }

                orderBy.Add((op, type, asc));

                if (Scanner.TryScan(",") == false)
                {
                    break;
                }
            } while (true);
            return(orderBy);
        }