public void DeleteWhere(TableName table, IWhereFragment @where) { if (table == null) throw new ArgumentNullException(nameof(table)); if (@where == null) throw new ArgumentNullException(nameof(@where)); Current().DeleteWhere(table, @where); }
public void Delete <T>(IWhereFragment where) { var delete = new Delete(typeof(T), where); var list = _deletes.GetOrAdd(typeof(T), _ => new List <Delete>()); list.Add(delete); }
public PatchExpression(IWhereFragment fragment, ITenant tenant, UnitOfWork unitOfWork, ISerializer serializer) { _fragment = fragment; _tenant = tenant; _unitOfWork = unitOfWork; _serializer = serializer; }
public DocumentStorage(DocumentMapping document) { _mapping = document; _document = document; Fields = document; TableName = document.Table; _defaultWhere = document.DefaultWhereFragment(); _selectClause = $"select {_document.SelectFields().Select(x => $"d.{x}").Join(", ")} from {document.Table.QualifiedName} as d"; _loaderSql = $"select {document.SelectFields().Join(", ")} from {document.Table.QualifiedName} as d where id = :id"; _loadArraySql = $"select {document.SelectFields().Join(", ")} from {document.Table.QualifiedName} as d where id = ANY(:ids)"; if (document.TenancyStyle == TenancyStyle.Conjoined) { _loaderSql += $" and {TenantWhereFragment.Filter}"; _loadArraySql += $" and {TenantWhereFragment.Filter}"; } QueryableDocument = document; UseOptimisticConcurrency = document.UseOptimisticConcurrency; _setter = LambdaBuilder.Setter <T, TId>(document.IdMember); }
public DeleteWhere(Type documentType, string sql, IWhereFragment @where, TenancyStyle tenancyStyle) { _where = @where; _tenancyStyle = tenancyStyle; DocumentType = documentType; Sql = sql; }
public PatchOperation(TransformFunction transform, IQueryableDocument document, IWhereFragment fragment, IDictionary <string, object> patch) { _transform = transform; _document = document; _fragment = fragment; _patch = patch; }
public PatchOperation(TransformFunction transform, IQueryableDocument document, IWhereFragment fragment, IDictionary<string, object> patch) { _transform = transform; _document = document; _fragment = fragment; _patch = patch; }
public IWhereFragment FilterDocuments(QueryModel model, IWhereFragment query) { var extras = extraFilters(query).ToArray(); var extraCoumpound = new CompoundWhereFragment("and", extras); return(new CompoundWhereFragment("and", query, extraCoumpound)); }
protected override Expression VisitConstant(ConstantExpression node) { if (node.Type == typeof(bool) && (bool)node.Value) { _top = new WhereFragment("true"); } return(base.VisitConstant(node)); }
public SubClassDocumentStorage(IDocumentStorage <TRoot, TId> parent, SubClassMapping mapping) { _parent = parent; _mapping = mapping; FromObject = _mapping.Table.QualifiedName; _defaultWhere = _mapping.DefaultWhereFragment(); }
public void DeleteWhere(TableName table, IWhereFragment @where) { if (table == null) throw new ArgumentNullException(nameof(table)); if (@where == null) throw new ArgumentNullException(nameof(@where)); var whereClause = @where.ToSql(_command); var call = new DeleteWhereCall(table, whereClause); _calls.Add(call); }
public static string AppendWhere(this string sql, IWhereFragment where, NpgsqlCommand command) { if (where == null) { return(sql); } return(sql + " where " + where.ToSql(command)); }
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()); } }
public void DeleteWhere(TableName table, IWhereFragment @where) { if (table == null) { throw new ArgumentNullException(nameof(table)); } if (@where == null) { throw new ArgumentNullException(nameof(@where)); } Current().DeleteWhere(table, @where); }
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)); }
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()); } }
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 static IWhereFragment[] Flatten(this IWhereFragment fragment) { if (fragment == null) { return(new IWhereFragment[0]); } if (fragment is CompoundWhereFragment c) { return(c.Children.ToArray()); } return(new [] { fragment }); }
public static IWhereFragment Append(this IWhereFragment fragment, IWhereFragment[] others) { if (!others.Any()) { return(fragment); } foreach (var other in others) { fragment = fragment.Append(other); } return(fragment); }
public static IWhereFragment Append(this IWhereFragment fragment, IWhereFragment other) { if (fragment is CompoundWhereFragment) { fragment.As <CompoundWhereFragment>().Add(other); return(fragment); } else if (other is CompoundWhereFragment) { other.As <CompoundWhereFragment>().Add(fragment); return(other); } return(new CompoundWhereFragment("and", fragment, other)); }
public void DeleteWhere(TableName table, IWhereFragment @where) { if (table == null) { throw new ArgumentNullException(nameof(table)); } if (@where == null) { throw new ArgumentNullException(nameof(@where)); } var whereClause = @where.ToSql(Command); var call = new DeleteWhereCall(table, whereClause); AddCall(call); }
public static IWhereFragment Append(this IWhereFragment fragment, IWhereFragment[] others) { if (others?.Any() == false) { return(fragment); } if (fragment == null) { return(Append(others.First(), others.Skip(1).ToArray())); } foreach (var other in others) { fragment = fragment.Append(other); } return(fragment); }
public DocumentStorage(DocumentMapping document) { _document = document; Fields = document; TableName = document.Table; _defaultWhere = document.DefaultWhereFragment(); _selectClause = $"select {_document.SelectFields().Join(", ")} from {document.Table.QualifiedName} as d"; _loaderSql = $"select {document.SelectFields().Join(", ")} from {document.Table.QualifiedName} as d where id = :id"; _loadArraySql = $"select {document.SelectFields().Join(", ")} from {document.Table.QualifiedName} as d where id = ANY(:ids)"; if (document.TenancyStyle == TenancyStyle.Conjoined) { _loaderSql += $" and {TenantWhereFragment.Filter}"; _loadArraySql += $" and {TenantWhereFragment.Filter}"; } }
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 DeleteWhere <T>(Expression <Func <T, bool> > expression) { assertNotDisposed(); var parser = new MartenExpressionParser(Options.Serializer(), Options); var model = MartenQueryParser.Flyweight.GetParsedQuery(Query <T>().Where(expression).As <MartenLinqQueryable <T> >().Expression); var storage = StorageFor <T>(); var whereClauses = model.BodyClauses.OfType <WhereClause>().ToArray(); // This is duplicated logic IWhereFragment where = null; switch (whereClauses.Length) { case 0: where = storage.DefaultWhereFragment(); break; case 1: where = parser.ParseWhereFragment(storage.Fields, whereClauses.Single().Predicate); break; default: where = new CompoundWhereFragment(parser, storage.Fields, "and", whereClauses); break; } where = storage.FilterDocuments(null, where); var deletion = storage.DeleteForWhere(@where); _unitOfWork.Add(deletion); }
public IWhereFragment FilterDocuments(QueryModel model, IWhereFragment query) { return(query); }
public Delete(Type documentType, IWhereFragment @where) { DocumentType = documentType; Where = @where; }
public IStorageOperation DeletionForWhere(IWhereFragment @where) { throw new NotImplementedException(); }
public WhereClauseVisitor(MartenExpressionParser parent, IQueryableDocument mapping) { _parent = parent; _mapping = mapping; _register.Push(x => _top = x); }
public IWhereFragment FilterDocuments(IWhereFragment query) { return new CompoundWhereFragment("and", DefaultWhereFragment(), query); }
public IWhereFragment FilterDocuments(IWhereFragment query) { throw new NotSupportedException(); }
public void DeleteWhere(string tableName, IWhereFragment @where) { Current().DeleteWhere(tableName, @where); }
public DeleteWhere(Type documentType, string sql, IWhereFragment @where) { _where = @where; DocumentType = documentType; Sql = sql; }
public void Add(IWhereFragment child) { _children.Add(child); }
public abstract IStorageOperation DeleteForWhere(IWhereFragment where);
public IWhereFragment FilterDocuments(QueryModel model, IWhereFragment query) { var extras = extraFilters(query).ToArray(); return(query.Append(extras)); }
protected override Expression VisitConstant(ConstantExpression node) { if ((node.Type == typeof(bool)) && (bool) node.Value) _top = new WhereFragment("true"); return base.VisitConstant(node); }
public IWhereFragment FilterDocuments(QueryModel model, IWhereFragment query) { return(_document.FilterDocuments(model, query)); }
public void DeleteWhere(string tableName, IWhereFragment @where) { var whereClause = @where.ToSql(_command); var call = new DeleteWhereCall(tableName, whereClause); _calls.Add(call); }
public IWhereFragment FilterDocuments(IWhereFragment query) { return(new CompoundWhereFragment("and", DefaultWhereFragment(), query)); }
public NotWhereFragment(IWhereFragment inner) { _inner = inner; }