// 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); }
public void ConfigureCommand(CommandBuilder builder) { var parts = Sql.Split('?'); builder.Append(parts[0]); _where.Apply(builder); builder.Append(parts[1]); }
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}"); } }
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}"); } }
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()); }
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); }
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); }
public void Apply(CommandBuilder builder) { builder.Append("NOT("); _inner.Apply(builder); builder.Append(")"); }