예제 #1
0
        /// <summary>
        /// Appends a call to <c>JSON_EXTRACT</c> from the current column and JSON path, e.g. <c>JSON_EXTRACT(T0."MyJson", '$.my.value')</c>, to the attribute buffer.
        /// </summary>
        /// <param name="attribute">The current attribute.</param>
        /// <returns>A new attribute containing the appended buffer.</returns>
        public static IProjectionAttribute Json(this IProjectionAttribute attribute)
        {
            IJsonMetadata json = attribute.Metadata.Identity.Require <IJsonMetadata>();

            IProjectionMetadata valueMetadata = attribute.Metadata;
            IProjectionMetadata rootMetadata  = json.MemberOf.Identity.Lookup <IProjectionMetadata>();

            attribute = attribute.Append("JSON_EXTRACT(");
            attribute = attribute.With(metadata: rootMetadata).Col();
            attribute = attribute.Append(",");
            attribute = attribute.With(metadata: valueMetadata).JsonPath();
            attribute = attribute.Append(")");

            return(attribute);
        }
예제 #2
0
        public static IProjection IsEq(this IProjection projection, IProjection other)
        {
            List <IProjectionAttribute> newAttrs = new List <IProjectionAttribute>();

            foreach (var(l, r) in projection.Attrs().Zip(other.Attrs()))
            {
                IProjectionAttribute newAttr = l;

                newAttr = newAttr.Eq();
                newAttr = newAttr.With(metadata: r.Metadata, field: r.Field).Par();
                newAttr = newAttr.With(metadata: l.Metadata, field: l.Field);

                newAttrs.Add(newAttr);
            }

            ProjectionOptions newOptions = new ProjectionOptions(projection.Options)
            {
                Separator = Environment.NewLine + "AND" + Environment.NewLine,
            };

            return(projection.With(attributes: newAttrs, options: newOptions));
        }
예제 #3
0
        public static IProjection IsEq(this IProjection projection, IProjection other)
        {
            List <IProjectionAttribute> newHeader = new List <IProjectionAttribute>();

            foreach (var(l, r) in projection.Attrs().Zip(other.Attrs()))
            {
                IProjectionAttribute newAttr = l;

                newAttr = newAttr.Eq();
                newAttr = newAttr.With(data: r.Data).Par();
                newAttr = newAttr.With(data: l.Data);

                newHeader.Add(newAttr);
            }

            ProjectionOptions newOptions = new ProjectionOptions(projection.Options)
            {
                Separator = Environment.NewLine + "AND" + Environment.NewLine,
            };

            return(projection.With(header: newHeader, options: newOptions));
        }
예제 #4
0
        public static IProjectionAttribute ValList(this IProjection projection, Func <IProjectionAttribute, IProjectionAttribute> itemFactory)
        {
            if (projection.Source == null)
            {
                throw ProjectionException.ValueNotFound(projection);
            }

            IField[]             items     = new Relation(projection.Source, projection.Metadata.Identity.Name).Column().ToArray();
            IProjectionAttribute attribute = projection.Attr();

            if (items.Length == 0)
            {
                return(attribute);
            }

            attribute = itemFactory(attribute.With(metadata: attribute.Metadata, field: () => items[0]));

            foreach (IField item in items.Skip(1))
            {
                attribute = itemFactory(attribute.With(field: () => item).Append(", "));
            }

            return(attribute);
        }