Path: redb/redb.Core/Query/ITreeQueryProvider.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Query/ITreeQueryProvider.cs
----
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using redb.Core.Caching;
using redb.Core.Models.Contracts;
using redb.Core.Models.Entities;
namespace redb.Core.Query;
///
/// Extended provider for executing tree LINQ queries.
/// Inherits base IRedbQueryProvider functionality and adds hierarchical constraint support.
///
public interface ITreeQueryProvider : IRedbQueryProvider
{
///
/// Metadata cache for this provider (domain-isolated).
///
GlobalMetadataCache Cache { get; }
///
/// Create tree query with hierarchical constraint support.
/// Uses SQL function search_tree_objects_with_facets() instead of search_objects_with_facets().
/// Returns IRedbQueryable with full tree method support.
///
/// Object scheme ID
/// User ID for permission check (null = current user)
/// Check object access permissions
/// Limit search to subtree of specified root (null = entire forest)
/// Maximum tree search depth (null = unlimited)
/// Typed query with tree operation support
IRedbQueryable CreateTreeQuery(
long schemeId,
long? userId = null,
bool checkPermissions = false,
long? rootObjectId = null,
int? maxDepth = null
) where TProps : class, new();
///
/// Get IDs of all objects and their parents to root via recursive CTE.
/// Used for building hierarchical relationships in ToTreeListAsync.
///
/// IDs of filtered objects
/// List of all IDs including parents to root
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task> GetIdsWithAncestorsAsync(List filteredIds,
CancellationToken cancellationToken = default) where TProps : class, new();
///
/// Load full typed objects by ID list via v_objects_json.
/// Used for loading homogeneous objects of one type.
///
/// Object IDs to load
/// Maximum depth for nested RedbObject loading (null = use config default)
/// List of TreeRedbObject with full data
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task>> LoadObjectsByIdsAsync(List objectIds, int? propsDepth = null,
CancellationToken cancellationToken = default) where TProps : class, new();
///
/// Load full untyped objects by ID list via v_objects_json.
/// Used for loading polymorphic trees (objects of different types).
/// Returns ITreeRedbObject for polymorphism support (each object of its own type).
///
/// Object IDs to load
/// Maximum depth for nested RedbObject loading (null = use config default)
/// List of polymorphic ITreeRedbObject (each of its own TProps type)
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task> LoadObjectsByIdsAsync(List objectIds, int? propsDepth = null,
CancellationToken cancellationToken = default);
///
/// Delete objects by ID array.
/// Used in TreeQueryable.DeleteAsync() to delete objects after filtering.
///
/// Object IDs to delete
/// Number of deleted objects
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task ExecuteTreeDeleteAsync(long[] objectIds,
CancellationToken cancellationToken = default);
///
/// Execute GROUP BY aggregation with tree context (CTE for tree traversal).
/// Used by TreeGroupedQueryable to perform tree-aware grouping.
///
/// Object properties type
/// Tree query context with rootObjectId, maxDepth, filters
/// Fields to group by
/// Aggregation functions to apply
/// HAVING predicate as the JSON HavingPredicateParser writes; null for none.
/// JSON document with grouped results
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task ExecuteTreeGroupedAggregateAsync(
Base.TreeQueryContext context,
IEnumerable groupFields,
IEnumerable aggregations,
string? havingJson = null,
CancellationToken cancellationToken = default) where TProps : class, new();
///
/// Execute Window Functions query with tree context (CTE for tree traversal).
/// Used by TreeWindowedQueryable to perform tree-aware window functions.
///
/// Object properties type
/// Tree query context with rootObjectId, maxDepth, filters
/// Fields to select
/// Window functions to apply
/// Partition by fields
/// Order by fields
/// Optional window frame specification
/// JSON document with windowed results
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task ExecuteTreeWindowQueryAsync(
Base.TreeQueryContext context,
IEnumerable selectFields,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
string? frameJson = null,
CancellationToken cancellationToken = default) where TProps : class, new();
///
/// Get SQL preview for tree window query (for debugging).
///
Task GetTreeWindowSqlPreviewAsync(
Base.TreeQueryContext context,
IEnumerable selectFields,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
string? frameJson = null,
CancellationToken cancellationToken = default) where TProps : class, new();
///
/// Get SQL preview for tree GROUP BY query (for debugging).
///
Task GetTreeGroupBySqlPreviewAsync(
Base.TreeQueryContext context,
IEnumerable groupFields,
IEnumerable aggregations,
string? havingJson = null,
CancellationToken cancellationToken = default) where TProps : class, new();
///
/// Runs a grouping over the elements of an array for the objects of a subtree: the objects the tree context
/// selects (its roots, depth and Where) take part, no others. and
/// must be null: the context carries the condition.
///
Task ExecuteTreeArrayGroupQueryAsync(
Base.TreeQueryContext context,
Grouping.ArrayGroupQuery query,
CancellationToken cancellationToken = default) where TProps : class, new();
///
/// The SQL runs for the same request.
///
Task GetTreeArrayGroupQuerySqlAsync(
Base.TreeQueryContext context,
Grouping.ArrayGroupQuery query,
CancellationToken cancellationToken = default) where TProps : class, new();
// ===== TREE GROUPED WINDOW (GroupBy + Window for Trees) =====
///
/// Execute GroupBy + Window Functions with tree context.
/// Allows ranking, running totals on aggregated tree data.
///
Task ExecuteTreeGroupedWindowQueryAsync(
Base.TreeQueryContext context,
IEnumerable groupFields,
IEnumerable aggregations,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
string? havingJson = null,
CancellationToken cancellationToken = default) where TProps : class, new();
///
/// Get SQL preview for tree GroupBy + Window query.
///
Task GetTreeGroupedWindowSqlPreviewAsync(
Base.TreeQueryContext context,
IEnumerable groupFields,
IEnumerable aggregations,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
string? havingJson = null,
CancellationToken cancellationToken = default) where TProps : class, new();
}