示例#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
        private IEnumerable <IWhereFragment> extraFilters(IWhereFragment query)
        {
            if (DeleteStyle == DeleteStyle.SoftDelete && !query.Contains(DeletedColumn))
            {
                yield return(ExcludeSoftDeletedDocuments());
            }

            if (_storeOptions.Tenancy.Style == TenancyStyle.Conjoined)
            {
                yield return(new TenantWhereFragment());
            }
        }
示例#3
0
        private IEnumerable <IWhereFragment> extraFilters(IWhereFragment query)
        {
            yield return(toBasicWhere());

            if (DeleteStyle == DeleteStyle.SoftDelete && !query.Contains(DocumentMapping.DeletedColumn))
            {
                yield return(DocumentMapping.ExcludeSoftDeletedDocuments());
            }

            if (Parent.TenancyStyle == TenancyStyle.Conjoined && !query.SpecifiesTenant())
            {
                yield return(new TenantWhereFragment());
            }
        }
示例#4
0
        public IWhereFragment FilterDocuments(QueryModel model, IWhereFragment query)
        {
            if (Parent.DeleteStyle == DeleteStyle.Remove)
            {
                return(new CompoundWhereFragment("and", DefaultWhereFragment(), query));
            }

            if (query.Contains(DocumentMapping.DeletedColumn))
            {
                return(new CompoundWhereFragment("and", toBasicWhere(), query));
            }

            return(new CompoundWhereFragment("and", DefaultWhereFragment(), query));
        }
示例#5
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);
        }
示例#6
0
 public bool Contains(string sqlText)
 {
     return("NOT".Contains(sqlText) || _inner.Contains(sqlText));
 }