Пример #1
0
        public static TypedExpression ArrayLength(TypedExpression exp)
        {
            RawQuery rq = new RawQuery();

            switch (exp.Type)
            {
            case KDPgValueTypeBinary _:
                rq.AppendFuncInvocation("octet_length", exp.RawQuery);
                break;

            case KDPgValueTypeString _:
                rq.AppendFuncInvocation("LENGTH", exp.RawQuery);
                break;

            case KDPgValueTypeArray _:
                rq.Append("array_length(");
                rq.Append(exp.RawQuery);
                rq.Append(",1)");
                break;

            default:
                throw new Exception("Invalid value to get array count");
            }

            return(new TypedExpression(rq, KDPgValueTypeInstances.Integer));
        }
Пример #2
0
        public RawQuery GetRawQuery()
        {
            RawQuery rq = _fromBuilder.GetRawQuery();

            var whereRawQuery = _whereBuilder.GetRawQuery();

            if (!whereRawQuery.IsEmpty)
            {
                rq.Append(" WHERE ");
                rq.Append(whereRawQuery);
            }

            if (_orderBuilder != null)
            {
                var r = _orderBuilder.GetRawQuery();
                if (!r.IsEmpty)
                {
                    rq.Append(" ORDER BY ");
                    rq.Append(r);
                }
            }

            if (_limitBuilder != null)
            {
                if (_limitBuilder.LimitValue.HasValue)
                {
                    rq.Append($" LIMIT {_limitBuilder.LimitValue}");
                }
                if (_limitBuilder.OffsetValue.HasValue)
                {
                    rq.Append($" OFFSET {_limitBuilder.OffsetValue}");
                }
            }

            if (_existsQuery)
            {
                var existsRq = new RawQuery();
                existsRq.AppendFuncInvocation("SELECT EXISTS", rq);
                rq = existsRq;
            }

            return(rq);
        }