Exemplo n.º 1
0
        public ModelRender(ModelDescriptor modelDefinition = null, StatementMasks masks = null)
        {
            Fragments = (IStatementFragments)typeof(TFragments).CreateInstance();
            WherePart = (IWherePart)typeof(TWherePart).CreateInstance();

            _modelDescriptor = modelDefinition ?? typeof(T).ToModelDescriptor();
            Masks            = masks;
        }
Exemplo n.º 2
0
        public static SqlBuilder.Template ToSqlBuilderTemplate(this Mutator mutator, Dictionary <string, MemberAttribute> settingsMembers = null, StatementMasks masks = null)
        {
            if (mutator == null)
            {
                return(null);
            }

            var ret = new SqlBuilder();

            var template = mutator.Transform.Statement;

            if (mutator.Transform?.Filter != null)
            {
                if (!template.Contains("where", StringComparison.InvariantCultureIgnoreCase))
                {
                    template += " /**where**/";
                }

                var parameterPrefix = masks.ParameterPrefix;

                var filter           = mutator.Transform?.Filter.FromJson <Dictionary <string, object> >();
                var filterParameters = filter.AddPrefix(parameterPrefix);

                var fieldSet = string.Join(", ", filter.Keys.Select(i => $"{i} = {parameterPrefix}{i}"));

                ret.OrWhere(fieldSet, filterParameters);
            }

            if (!string.IsNullOrEmpty(mutator.Transform.OrderBy))
            {
                if (!template.Contains("/**orderby**/"))
                {
                    template += " /**orderby**/";
                }

                var field     = mutator.Transform.OrderBy;
                var direction = "";

                if (field[0] == '-')
                {
                    field     = field.Substring(1);
                    direction = " DESC";
                }

                if (field[0] == '+')
                {
                    field = field.Substring(1);
                }

                if (settingsMembers != null)
                {
                    if (settingsMembers.ContainsKey(field))
                    {
                        field = settingsMembers[field].TargetName;
                    }
                }
                ret.OrderBy(field + direction);
            }

            var selector = ret.AddTemplate(template);

            ret.Select(mutator.Transform?.OutputMembers ?? "*");

            return(selector);
        }
Exemplo n.º 3
0
 public static SqlBuilder.Template ToSqlBuilderTemplate <T>(this Mutator mutator, Settings <T> settings, StatementMasks masks) where T : Data <T> => mutator.ToSqlBuilderTemplate(settings.Members, masks);