コード例 #1
0
        public static QsiTableNode VisitQuerySpecification(QuerySpecificationContext context)
        {
            var node = new PrimarSqlDerivedTableNode
            {
                SelectSpec = VisitSelectSpec(context.selectSpec())
            };

            node.Columns.SetValue(VisitSelectElements(context.selectElements()));

            if (context.fromClause() != null)
            {
                node.Source.SetValue(VisitFromCluase(context.fromClause()));

                if (context.fromClause().whereExpr != null)
                {
                    node.Where.SetValue(VisitWhereExpression(context.fromClause()));
                }
            }

            if (context.orderClause() != null)
            {
                node.Order.SetValue(TreeHelper.Create <QsiMultipleOrderExpressionNode>(n =>
                {
                    n.Orders.Add(ExpressionVisitor.VisitOrderCluase(context.orderClause()));

                    PrimarSqlTree.PutContextSpan(n, context.orderClause());
                }));
            }

            if (context.limitClause() != null)
            {
                node.Limit.SetValue(ExpressionVisitor.VisitLimitClause(context.limitClause()));
            }

            if (context.startKeyClause() != null)
            {
                node.StartKey.SetValue(ExpressionVisitor.VisitStartKeyClause(context.startKeyClause()));
            }

            PrimarSqlTree.PutContextSpan(node, context);

            return(node);
        }
コード例 #2
0
        public static SelectQueryInfo VisitQuerySpecification(QuerySpecificationContext context)
        {
            var queryInfo = new SelectQueryInfo();

            var fromClause = context.fromClause();

            if (context.selectSpec() != null)
            {
                if (context.selectSpec().STRONGLY() != null)
                {
                    queryInfo.UseStronglyConsistent = true;
                }
            }

            queryInfo.Columns = VisitSelectElements(context.selectElements());

            if (fromClause == null)
            {
                queryInfo.TableSource = null;
            }
            else
            {
                queryInfo.TableSource = VisitTableSource(fromClause.tableSource());

                if (fromClause.whereExpr != null)
                {
                    queryInfo.WhereExpression = ExpressionVisitor.VisitExpression(fromClause.whereExpr);
                }
            }

            if (context.orderClause() != null)
            {
                if (queryInfo.WhereExpression == null)
                {
                    throw new NotSupportedException("DynamoDB Not support ORDER clause without condition expression.");
                }

                if (context.orderClause().DESC() != null)
                {
                    queryInfo.OrderDescend = true;
                }
            }

            if (context.limitClause() != null)
            {
                var limitClause = context.limitClause();

                if (int.TryParse(limitClause.limit.GetText(), out int limit))
                {
                    queryInfo.Limit = limit;
                }

                if (limitClause.offset != null)
                {
                    if (int.TryParse(limitClause.offset.GetText(), out int offset))
                    {
                        queryInfo.Offset = offset;
                    }
                }
            }

            if (context.startKeyClause() != null)
            {
                var startKeyClause = context.startKeyClause();

                queryInfo.StartHashKey = ExpressionVisitor.VisitConstant(startKeyClause.hashKey);

                if (startKeyClause.sortKey != null)
                {
                    queryInfo.StartSortKey = ExpressionVisitor.VisitConstant(startKeyClause.sortKey);
                }
            }

            return(queryInfo);
        }