示例#1
0
        // TODO -- come back and do this with a single command!
        public void ConfigureCommand(CommandBuilder builder)
        {
            var patchJson    = _serializer.ToCleanJson(_patch);
            var patchParam   = builder.AddJsonParameter(patchJson);
            var versionParam = builder.AddParameter(CombGuidIdGeneration.NewGuid(), NpgsqlDbType.Uuid);

            builder.Append("update ");
            builder.Append(_document.Table.QualifiedName);
            builder.Append(" as d set data = ");
            builder.Append(_transform.Identifier.QualifiedName);
            builder.Append("(data, :");
            builder.Append(patchParam.ParameterName);
            builder.Append("), ");
            builder.Append(DocumentMapping.LastModifiedColumn);
            builder.Append(" = (now() at time zone 'utc'), ");
            builder.Append(DocumentMapping.VersionColumn);
            builder.Append(" = :");
            builder.Append(versionParam.ParameterName);

            if (!_fragment.Contains("where"))
            {
                builder.Append(" where ");
            }
            else
            {
                builder.Append(" ");
            }

            _fragment.Apply(builder);

            applyUpdates(builder, _fragment);
        }
示例#2
0
        public void ConfigureCommand(CommandBuilder builder)
        {
            var parts = Sql.Split('?');

            builder.Append(parts[0]);
            _where.Apply(builder);
            builder.Append(parts[1]);
        }
示例#3
0
        public void ConfigureCommand(CommandBuilder builder)
        {
            var parts = Sql.Split('?');

            builder.Append(parts[0]);
            _where.Apply(builder);
            builder.Append(parts[1]);

            if (_tenancyStyle == TenancyStyle.Conjoined)
            {
                builder.Append($" and {TenantWhereFragment.Filter}");
            }
        }
示例#4
0
        public void ConfigureCommand(CommandBuilder builder)
        {
            var parts = Sql.Split('?');

            builder.Append(parts[0]);
            _where.Apply(builder);
            builder.Append(parts[1]);

            if (_tenancyStyle == TenancyStyle.Conjoined)
            {
                builder.Append($" and {TenantIdColumn.Name} = :{TenantIdArgument.ArgName}");
            }
        }
示例#5
0
        public static string ToSql(this IWhereFragment fragment)
        {
            if (fragment == null)
            {
                return(null);
            }

            var cmd     = new NpgsqlCommand();
            var builder = new CommandBuilder(cmd);

            fragment.Apply(builder);

            return(builder.ToString().Trim());
        }
示例#6
0
        public void ConfigureCommand(CommandBuilder builder, IMartenSession session)
        {
            var patchParam = builder.AddJsonParameter(_serializer.ToCleanJson(_patch));

            if (_patch.ContainsKey("value"))
            {
                var value = _serializer.ToJson(_patch["value"]);
                var copy  = new Dictionary <string, object>();
                foreach (var item in _patch)
                {
                    copy.Add(item.Key, item.Value);
                }
                copy["value"] = VALUE_LOOKUP;

                var patchJson     = _serializer.ToCleanJson(copy);
                var replacedValue = patchJson.Replace($"\"{VALUE_LOOKUP}\"", value);

                patchParam = builder.AddJsonParameter(replacedValue);
            }

            var versionParam = builder.AddParameter(CombGuidIdGeneration.NewGuid(), NpgsqlDbType.Uuid);

            builder.Append("update ");
            builder.Append(_document.Table.QualifiedName);
            builder.Append(" as d set data = ");
            builder.Append(_transform.Identifier.QualifiedName);
            builder.Append("(data, :");
            builder.Append(patchParam.ParameterName);
            builder.Append("), ");
            builder.Append(DocumentMapping.LastModifiedColumn);
            builder.Append(" = (now() at time zone 'utc'), ");
            builder.Append(DocumentMapping.VersionColumn);
            builder.Append(" = :");
            builder.Append(versionParam.ParameterName);

            if (!_fragment.Contains("where"))
            {
                builder.Append(" where ");
            }
            else
            {
                builder.Append(" ");
            }

            _fragment.Apply(builder);

            applyUpdates(builder, _fragment);
        }
示例#7
0
        private void applyUpdates(CommandBuilder builder, IWhereFragment where)
        {
            var fields = _document.DuplicatedFields;

            if (!fields.Any())
            {
                return;
            }

            builder.Append(";update ");
            builder.Append(_document.Table.QualifiedName);
            builder.Append(" as d set ");

            builder.Append(fields[0].UpdateSqlFragment());
            for (var i = 1; i < fields.Length; i++)
            {
                builder.Append(", ");
                builder.Append(fields[i].UpdateSqlFragment());
            }

            builder.Append(" where ");
            where.Apply(builder);
        }
示例#8
0
 public void Apply(CommandBuilder builder)
 {
     builder.Append("NOT(");
     _inner.Apply(builder);
     builder.Append(")");
 }