Path: redb/redb.Core/Query/IRedbQueryProvider.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/IRedbQueryProvider.cs
----
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using redb.Core.Models.Contracts;
using redb.Core.Query.Aggregation;
using redb.Core.Query.QueryExpressions;
namespace redb.Core.Query;
///
/// Provider for executing LINQ queries.
///
public interface IRedbQueryProvider
{
///
/// Create new query for specified scheme.
///
IRedbQueryable CreateQuery(long schemeId, long? userId = null, bool checkPermissions = false)
where TProps : class, new();
///
/// Execute query asynchronously.
///
Task ExecuteAsync(Expression expression, Type elementType,
CancellationToken cancellationToken = default);
///
/// Get scheme by ID (for projections).
///
Task GetSchemeAsync(long schemeId,
CancellationToken cancellationToken = default);
// ===== AGGREGATIONS (EAV) =====
///
/// Execute aggregation on EAV field (SQL strategy for simple fields).
///
/// Scheme ID
/// Field path (e.g. "Price")
/// Aggregation function
/// JSON filter (as for search_objects)
/// Aggregation result
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task ExecuteAggregateAsync(
long schemeId,
string fieldPath,
AggregateFunction function,
string? filterJson = null,
CancellationToken cancellationToken = default);
///
/// Execute batch aggregation (multiple fields in one query).
///
Task ExecuteAggregateBatchAsync(
long schemeId,
IEnumerable requests,
string? filterJson = null,
CancellationToken cancellationToken = default);
///
/// Execute single-field aggregation with FilterExpression (Pro version).
///
Task ExecuteAggregateAsync(
long schemeId,
string fieldPath,
AggregateFunction function,
FilterExpression? filter,
CancellationToken cancellationToken = default);
///
/// Execute batch aggregation with FilterExpression (Pro version).
///
Task ExecuteAggregateBatchAsync(
long schemeId,
IEnumerable requests,
FilterExpression? filter,
CancellationToken cancellationToken = default);
// ===== GROUPBY AGGREGATIONS =====
///
/// Execute GroupBy aggregation. Uses filterJson for Free version compatibility.
/// is a PVT-shape HAVING predicate; pass null when none.
///
Task ExecuteGroupedAggregateAsync(
long schemeId,
IEnumerable groupFields,
IEnumerable aggregations,
string? filterJson = null,
string? havingJson = null,
CancellationToken cancellationToken = default);
///
/// Execute GroupBy aggregation with FilterExpression (Pro version).
/// Provides direct access to filter for proper SQL compilation.
/// carries the PVT-shape HAVING predicate when present.
///
Task ExecuteGroupedAggregateAsync(
long schemeId,
IEnumerable groupFields,
IEnumerable aggregations,
FilterExpression? filter,
string? havingJson = null,
CancellationToken cancellationToken = default);
///
/// The SQL
/// runs, for ToSqlStringAsync .
///
Task GetGroupBySqlPreviewAsync(
long schemeId,
IEnumerable groupFields,
IEnumerable aggregations,
string? filterJson,
string? havingJson = null,
CancellationToken cancellationToken = default);
///
/// The SQL
/// runs, for ToSqlStringAsync .
///
Task GetGroupBySqlPreviewAsync(
long schemeId,
IEnumerable groupFields,
IEnumerable aggregations,
FilterExpression? filter,
string? havingJson = null,
CancellationToken cancellationToken = default);
///
/// Runs a grouping over the elements of an array (GroupByArray, with or without a window over the groups) and
/// returns its rows as a JSON array of objects, one property per key and aggregate alias, NULL values included.
///
Task ExecuteArrayGroupQueryAsync(
Grouping.ArrayGroupQuery query,
CancellationToken cancellationToken = default);
///
/// The SQL runs for the same request, for ToSqlStringAsync .
///
Task GetArrayGroupQuerySqlAsync(
Grouping.ArrayGroupQuery query,
CancellationToken cancellationToken = default);
// ===== WINDOW FUNCTIONS =====
///
/// Execute query with window functions (SQL function query_with_window).
///
Task ExecuteWindowQueryAsync(
long schemeId,
IEnumerable selectFields,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
string? filterJson = null,
string? frameJson = null,
int? take = null,
int? skip = null,
CancellationToken cancellationToken = default);
///
/// Execute query with window functions with FilterExpression (Pro version).
///
Task ExecuteWindowQueryAsync(
long schemeId,
IEnumerable selectFields,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
FilterExpression? filter,
string? frameJson = null,
int? take = null,
int? skip = null,
CancellationToken cancellationToken = default);
///
/// Get SQL preview for window query (for debugging).
///
Task GetWindowSqlPreviewAsync(
long schemeId,
IEnumerable selectFields,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
string? filterJson = null,
string? frameJson = null,
int? take = null,
int? skip = null,
CancellationToken cancellationToken = default);
///
/// Get SQL preview for window query with FilterExpression (Pro version): the SQL that
///
/// runs for the same arguments.
///
Task GetWindowSqlPreviewAsync(
long schemeId,
IEnumerable selectFields,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
QueryExpressions.FilterExpression? filter,
string? frameJson = null,
int? take = null,
int? skip = null,
CancellationToken cancellationToken = default)
// A default body keeps implementations outside redb compiling; QueryProviderBase overrides it.
=> throw new NotSupportedException(
$"{GetType().Name} has no SQL preview of a window query with a FilterExpression; implement this overload " +
"of GetWindowSqlPreviewAsync.");
// ===== GROUPED WINDOW (GroupBy + Window Functions) =====
///
/// Execute GroupBy with Window Functions (ranking, running totals on aggregated data).
///
Task ExecuteGroupedWindowQueryAsync(
long schemeId,
IEnumerable groupFields,
IEnumerable aggregations,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
string? filterJson = null,
string? havingJson = null,
CancellationToken cancellationToken = default);
///
/// Execute GroupBy with Window Functions with FilterExpression (Pro version).
///
Task ExecuteGroupedWindowQueryAsync(
long schemeId,
IEnumerable groupFields,
IEnumerable aggregations,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
FilterExpression? filter,
string? havingJson = null,
CancellationToken cancellationToken = default);
///
/// Get SQL preview for GroupBy + Window query.
///
Task GetGroupedWindowSqlPreviewAsync(
long schemeId,
IEnumerable groupFields,
IEnumerable aggregations,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
string? filterJson = null,
string? havingJson = null,
CancellationToken cancellationToken = default);
///
/// Get SQL preview for GroupBy + Window query with FilterExpression (Pro version).
///
Task GetGroupedWindowSqlPreviewAsync(
long schemeId,
IEnumerable groupFields,
IEnumerable aggregations,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
FilterExpression? filter,
string? havingJson = null,
CancellationToken cancellationToken = default);
// ===== DELETE =====
///
/// Delete objects by filter: the objects of the scheme the filter selects, null for every object of the scheme.
///
/// Scheme ID
/// Filter expression from LINQ
/// Number of deleted objects
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task ExecuteDeleteAsync(long schemeId, FilterExpression? filter,
CancellationToken cancellationToken = default);
// ===== SQL PREVIEW =====
///
/// Get SQL query for debugging (analogous to ToQueryString in EF Core).
/// Pro version returns PVT SQL, Open Source - redb_json_objects.
///
Task GetSqlPreviewAsync(QueryContext context,
CancellationToken cancellationToken = default) where TProps : class, new();
///
/// Returns the JSON filter that will be sent to SQL function (for diagnostics)
///
Task GetFilterJsonAsync(QueryContext context,
CancellationToken cancellationToken = default) where TProps : class, new();
}