Ejemplo n.º 1
0
        public SelectorStatement ToSelectMany(IField collectionField, IMartenSession session, bool isComplex,
                                              Type elementType)
        {
            if (elementType.IsSimple())
            {
                var selection = $"jsonb_array_elements_text({collectionField.JSONBLocator})";

                SelectClause = typeof(DataSelectClause <>).CloseAndBuildAs <ISelectClause>(SelectClause.FromObject, selection,
                                                                                           elementType);

                Mode       = StatementMode.CommonTableExpression;
                ExportName = session.NextTempTableName() + "CTE";

                var next = elementType == typeof(string)
                    ? new ScalarSelectManyStringStatement(this)
                    : typeof(ScalarSelectManyStatement <>).CloseAndBuildAs <Statement>(this, session.Serializer, elementType);

                InsertAfter(next);

                return((SelectorStatement)next);
            }

            var childFields = session.Options.ChildTypeMappingFor(elementType);

            if (isComplex)
            {
                var selection = $"jsonb_array_elements({collectionField.JSONBLocator})";
                SelectClause = typeof(DataSelectClause <>).CloseAndBuildAs <ISelectClause>(SelectClause.FromObject, selection,
                                                                                           elementType);

                Mode       = StatementMode.CommonTableExpression;
                ExportName = session.NextTempTableName() + "CTE";

                var statement = new JsonStatement(elementType, childFields, this);

                InsertAfter(statement);

                return(statement);
            }
            else
            {
                var selection = $"jsonb_array_elements_text({collectionField.JSONBLocator})";
                SelectClause = typeof(DataSelectClause <>).CloseAndBuildAs <ISelectClause>(SelectClause.FromObject, selection,
                                                                                           elementType);

                return(this);
            }
        }
Ejemplo n.º 2
0
        public override SelectorStatement UseAsEndOfTempTableAndClone(IncludeIdentitySelectorStatement includeIdentitySelectorStatement)
        {
            includeIdentitySelectorStatement.IncludeDataInTempTable = true;

            var clone = new JsonStatement(SelectClause, Fields)
            {
                SelectClause = SelectClause.As <IScalarSelectClause>().CloneToOtherTable(includeIdentitySelectorStatement.ExportName),
                Orderings    = Orderings,
                Mode         = StatementMode.Select,
                ExportName   = ExportName
            };

            SelectClause = includeIdentitySelectorStatement;

            Limit = Offset = 0;

            return(clone);
        }