Ejemplo n.º 1
0
 public static ValueNode AliasedCol <TTable>(AggregateType type, ValueNode parameter, string alias)
 {
     return(ValueNode.NewNamedColumn(
                new AliasedColumnNode(
                    ValueNode.NewAggregate(new Tuple <AggregateType, ValueNode>(type, parameter)),
                    alias)));
 }
Ejemplo n.º 2
0
 public static OrderByClauseNode OrderClause(ValueNode col, Direction direction, NullsOrdering nullsOrdering = null)
 {
     return(new OrderByClauseNode(
                direction,
                nullsOrdering ?? NullsOrdering.NullsUndefined,
                col));
 }
Ejemplo n.º 3
0
 public static JoinClauseNode Join <TSource, TTarget>(JoinType type, ValueNode joinExpr)
 {
     return(new JoinClauseNode(
                new FSharpList <ITableIdentifier>(new TableIdentifier <TSource>(), FSharpList <ITableIdentifier> .Empty),
                new TableIdentifier <TTarget>(),
                type,
                joinExpr.ToOption()));
 }
Ejemplo n.º 4
0
 public static ValueNode AliasedCol(
     string alias,
     AggregateType type,
     ValueNode aggregateParameter,
     IEnumerable <ValueNode> partitionBy     = null,
     IEnumerable <OrderByClauseNode> orderBy = null)
 {
     return(ValueNode.NewNamedColumn(
                new AliasedColumnNode(
                    WinCol(type, aggregateParameter, partitionBy, orderBy),
                    alias)));
 }
Ejemplo n.º 5
0
 public static JoinClauseNode Join <TSource1, TSource2, TTarget>(
     ITableIdentifier <TSource1> source1,
     ITableIdentifier <TSource2> source2,
     ITableIdentifier <TTarget> target,
     JoinType type,
     ValueNode joinExpr)
 {
     return(new JoinClauseNode(
                ListModule.OfArray(new ITableIdentifier[] { source1, source2 }),
                target,
                type,
                joinExpr.ToOption()));
 }
Ejemplo n.º 6
0
 public static ValueNode WinCol(
     AggregateType type,
     ValueNode aggregateParameter,
     IEnumerable <ValueNode> partitionBy     = null,
     IEnumerable <OrderByClauseNode> orderBy = null)
 {
     return(ValueNode.NewWindowedColumn(
                new Tuple <Tuple <AggregateType, ValueNode>, AST.WindowNode>(
                    new Tuple <AggregateType, ValueNode>(type, aggregateParameter),
                    new AST.WindowNode(
                        partitionBy == null ? ListModule.Empty <ValueNode>() : ListModule.OfSeq(partitionBy),
                        orderBy == null ? ListModule.Empty <OrderByClauseNode>() : ListModule.OfSeq(orderBy)))));
 }
Ejemplo n.º 7
0
        public void ItCanVisitAMultipleColumnSelector()
        {
            Expression <Func <Person, object> > func = (Person p) => new { p.Age, p.Name };
            var tableRef = Types.TableReferenceFromType <Person>();
            var ev       = ExpressionVisitor.Visit(
                ExpressionVisitor.VisitableExpression.NewLinqExpression(func),
                new[] { tableRef }.ToContext()
                );

            var expected =
                ValueNode.NewValueList(
                    ListModule.OfArray(new[] { S.Col <Person>("Age"), S.Col <Person>("Name") })).ToOption();

            Assert.That(ev, Is.EqualTo(expected));
        }
Ejemplo n.º 8
0
 public static ValueNode SubExp(
     SelectValuesExpressionNode select,
     FromExpressionNode from,
     WhereExpressionNode where     = null,
     GroupByExpressionNode groupBy = null,
     OrderByExpressionNode orderBy = null)
 {
     return(ValueNode.NewSubExpression(
                PlainSelectExpression.NewPlain(
                    new SelectExpressionToken(
                        select,
                        from,
                        where.ToOption(),
                        groupBy.ToOption(),
                        orderBy.ToOption()))));
 }
Ejemplo n.º 9
0
 public static ValueNode SubExp(
     SelectValuesExpressionNode select,
     FromExpressionNode from,
     WhereExpressionNode where     = null,
     GroupByExpressionNode groupBy = null,
     OrderByExpressionNode orderBy = null,
     LimitOffsetNode limitOffset   = null)
 {
     return(ValueNode.NewSubExpression(
                PlainSelectExpression.NewPlain(
                    new SelectExpressionToken(
                        select,
                        from,
                        where.ToOption(),
                        groupBy.ToOption(),
                        orderBy.ToOption(),
                        limitOffset ?? new LimitOffsetNode(FSharpOption <int> .None, FSharpOption <int> .None)))));
 }
Ejemplo n.º 10
0
        public void ItShouldBeAbleToGenerateAliasesForBinaryExpressions()
        {
            Expression <Func <Person, object> > func = (Person p) => new { AgePlusTen = p.Age + 10 };
            var tableRefs = new[]
            {
                Types.TableReferenceFromType <Person>(),
            };
            var ev = ExpressionVisitor.Visit(
                ExpressionVisitor.VisitableExpression.NewLinqExpression(func),
                tableRefs.ToContext());

            var expected =
                ValueNode.NewValueList(
                    ListModule.OfArray(new[] {
                S.AliasedCol(S.BinExp(S.Col <Person>("Age"), BinaryOperation.Add, S.Const(10)), "AgePlusTen"),
            })).ToOption();

            Assert.That(ev, Is.EqualTo(expected));
        }
Ejemplo n.º 11
0
        public void ItShouldNotGenerateAliasColumnsForColumnsBeingAliasedToItsOrdinaryName()
        {
            Expression <Func <Person, object> > func = (Person p) => new { Name = p.Name, Age = p.Age };
            var tableRefs = new[]
            {
                Types.TableReferenceFromType <Person>(),
            };
            var ev = ExpressionVisitor.Visit(
                ExpressionVisitor.VisitableExpression.NewLinqExpression(func),
                tableRefs.ToContext());
            var expected =
                ValueNode.NewValueList(
                    ListModule.OfArray(new[] {
                S.Col <Person>("Name"),
                S.Col <Person>("Age"),
            })).ToOption();

            Assert.That(ev, Is.EqualTo(expected));
        }
Ejemplo n.º 12
0
        public void ItShouldBeAbleToGenerateAliasesForConstants()
        {
            Expression <Func <Person, object> > func = (Person p) => new { FavoriteNumber = 42 };
            var tableRefs = new[]
            {
                Types.TableReferenceFromType <Person>(),
            };
            var ev = ExpressionVisitor.Visit(
                ExpressionVisitor.VisitableExpression.NewLinqExpression(func),
                tableRefs.ToContext());

            var expected =
                ValueNode.NewValueList(
                    ListModule.OfArray(new[] {
                S.AliasedCol(S.Const(42), "FavoriteNumber"),
            })).ToOption();

            Assert.That(ev, Is.EqualTo(expected));
        }
Ejemplo n.º 13
0
        public void ItShouldBeAbleToGenerateAliasedColumnTokens()
        {
            Expression <Func <Person, object> > func = (Person p) => new { p.Name, AgeOfPerson = p.Age, Count = Sql.Count() };
            var tableRefs = new[]
            {
                Types.TableReferenceFromType <Person>(),
            };
            var ev = ExpressionVisitor.Visit(
                ExpressionVisitor.VisitableExpression.NewLinqExpression(func),
                tableRefs.ToContext());

            var expected =
                ValueNode.NewValueList(
                    ListModule.OfArray(new[] {
                S.Col <Person>("Name"),
                S.AliasedCol <Person>("Age", "AgeOfPerson"),
                S.AliasedCol <Person>(AST.AggregateType.Count, S.Null(), "Count")
            })).ToOption();

            Assert.That(ev, Is.EqualTo(expected));
        }
Ejemplo n.º 14
0
 public static ValueNode AliasedCol(ValueNode node, string alias)
 {
     return(ValueNode.NewNamedColumn(new AliasedColumnNode(node, alias)));
 }
Ejemplo n.º 15
0
 public static ValueNode Star <TTable>()
 {
     return(ValueNode.NewStarColumn(Types.TableReferenceFromType <TTable>()));
 }
Ejemplo n.º 16
0
 public static ValueNode Col(ITableReference r, string colDef)
 {
     return(ValueNode.NewColumn(new Tuple <string, Type, ITableReference>(colDef, FigureOutTypeFor(colDef, r), r)));
 }
Ejemplo n.º 17
0
        public static ValueNode Col <TTable>(TableReferenceCreator <TTable> c, string colDef)
        {
            var tref = c.ToTableReference().Reference;

            return(ValueNode.NewColumn(new Tuple <string, Type, ITableReference>(colDef, FigureOutTypeFor(colDef, tref), tref)));
        }
Ejemplo n.º 18
0
 public static ValueNode Col <TTable>(ITableIdentifier <TTable> r, string columnDef)
 {
     return(ValueNode.NewColumn(new Tuple <string, Type, ITableReference>(columnDef, FigureOutTypeFor(columnDef, r.Reference), r.Reference)));
 }
Ejemplo n.º 19
0
 public static UpdateSetToken Ust <TTableType>(string colDef, ValueNode node)
 {
     return(CreateUpdateSetToken <TTableType>(colDef, node));
 }
Ejemplo n.º 20
0
 public static WhereExpressionNode Where(ValueNode start, params WhereClauseNode[] additionalClauses)
 {
     return
         (new WhereExpressionNode(start, ListModule.OfArray(additionalClauses)));
 }
Ejemplo n.º 21
0
 public static ValueNode Aggregate(AggregateType type, ValueNode parameter)
 {
     return(ValueNode.NewAggregate(new Tuple <AggregateType, ValueNode>(type, parameter)));
 }
Ejemplo n.º 22
0
        public static ValueNode AliasedCol <TTable>(string colDef, string alias)
        {
            var tref = Types.TableReferenceFromType <TTable>();

            return(AliasedCol(ValueNode.NewColumn(new Tuple <string, Type, ITableReference>(colDef, FigureOutTypeFor(colDef, tref), tref)), alias));
        }
Ejemplo n.º 23
0
 public static ValueNode BinExp(ValueNode lhs, BinaryOperation op, ValueNode rhs)
 {
     return(ValueNode.NewBinaryExpression(new BinaryExpressionNode(lhs, op, rhs)));
 }
Ejemplo n.º 24
0
 public static ValueNode Func(FunctionType type, params ValueNode[] arguments)
 {
     return(ValueNode.NewFunctionCall(
                new Tuple <FunctionType, FSharpList <ValueNode> >(type, ListModule.OfArray(arguments))));
 }
Ejemplo n.º 25
0
 public static ValueNode Const(object constant)
 {
     return(ValueNode.NewConstant(constant.ToString()));
 }
Ejemplo n.º 26
0
 public static WhereClauseNode Or(ValueNode stream)
 {
     return(new WhereClauseNode(ExpressionCombinatorType.Or, stream));
 }
Ejemplo n.º 27
0
        private static UpdateSetToken CreateUpdateSetToken <TTableType>(string colDef, ValueNode stream)
        {
            var tref = Types.TableReferenceFromType <TTableType>();

            return(new UpdateSetToken(new Tuple <string, Type, ITableReference>(colDef, FigureOutTypeFor(colDef, tref), tref), stream));
        }
Ejemplo n.º 28
0
        public static ValueNode Col <TTableType>(string columnDef)
        {
            var tref = Types.TableReferenceFromType <TTableType>();

            return(ValueNode.NewColumn(new Tuple <string, Type, ITableReference>(columnDef, FigureOutTypeFor(columnDef, tref), tref)));
        }
Ejemplo n.º 29
0
 public static ValueNode Param(string paramName)
 {
     return(ValueNode.NewParameter(paramName));
 }