@algochad/prisma-core
Version:
A comprehensive NestJS library that provides EF-Core-like operations using Prisma and GraphQL. Features LINQ-style query builders, advanced data manipulation, GraphQL integration with genql, and a unified API for both Prisma and GraphQL operations. Includ
139 lines (138 loc) • 13 kB
TypeScript
import { IQueryable, IOrderedQueryable, IQueryProvider, IGrouping } from '../efcore/queryable-interfaces';
import { IAsyncEnumerable } from '../linq/interfaces';
import { Enumerable } from '../linq/enumerable';
import { List } from '../linq/list';
import { LinqQueryContext } from './linq-query-context';
export interface IPrismaQueryExpression {
where?: any;
select?: any;
include?: any;
orderBy?: any[];
take?: number;
skip?: number;
distinct?: boolean | string[] | Function[];
groupBy?: string[] | Function[];
having?: any;
modelName?: string;
isTracking?: boolean;
inMemoryPredicates?: Array<(item: any) => boolean | Promise<boolean>>;
expectedResult?: Record<string, any>;
}
export declare class PrismaQueryProvider implements IQueryProvider {
private prismaModel;
private modelName;
constructor(prismaModel: any, modelName?: string);
Execute<TResult>(expression: IPrismaQueryExpression): Promise<TResult>;
CreateQuery<TModel, TElement, TWhereInput = any, TOrderByInput = any, TInclude = any, TSelectInput = any, TCreateInput = any, TUpdateInput = any, TWhereUniqueInput = any>(expression: IPrismaQueryExpression): IQueryable<TModel, TElement, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
}
export declare class PrismaQueryable<TModel = unknown, TSelect = TModel, TWhereInput = any, TOrderByInput = any, TInclude = any, TSelectInput = any, TCreateInput = any, TUpdateInput = any, TWhereUniqueInput = any> implements IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput> {
protected provider: PrismaQueryProvider;
protected expression: IPrismaQueryExpression;
protected elementType: any;
protected linqContext?: LinqQueryContext;
constructor(provider: PrismaQueryProvider, expression?: IPrismaQueryExpression, elementType?: any, linqContext?: LinqQueryContext);
get Provider(): IQueryProvider;
get Expression(): any;
get ElementType(): any;
private createNew;
WhereFilter(where: TWhereInput): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
SelectFields<TSelectFields extends TSelectInput>(select: TSelectFields): IQueryable<TModel, TSelectFields, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Include(include: TInclude): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
private mergeIncludes;
OrderBy(orderBy: TOrderByInput): IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
SelectMany<TResult>(selector: (item: TSelect) => IQueryable<any, TResult> | IAsyncEnumerable<TResult>): IQueryable<TModel, TResult, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
GroupBy<TKey, TElement = TSelect, TResult = IGrouping<TKey, TElement>>(keySelector: (item: TSelect) => TKey, elementSelector?: (item: TSelect) => TElement, resultSelector?: (key: TKey, group: IQueryable<TModel, TElement>) => TResult): IQueryable<TModel, TResult, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Join<TInner, TKey, TResult>(inner: IQueryable<any, TInner>, outerKeySelector: (outer: TSelect) => TKey, innerKeySelector: (inner: TInner) => TKey, resultSelector: (outer: TSelect, inner: TInner) => TResult): IQueryable<TModel, TResult, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Union(other: IQueryable<TModel, TSelect>): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Intersect(other: IQueryable<TModel, TSelect>): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Except(other: IQueryable<TModel, TSelect>): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Take(count: number): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Skip(count: number): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Distinct<TKey>(keySelector?: (item: TSelect) => TKey): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Where: (where: TWhereInput) => IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Select: <TSelectFields extends TSelectInput>(select: TSelectFields) => IQueryable<TModel, TSelectFields, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
ExecuteAsync(): Promise<TSelect[]>;
ToArrayAsync(): Promise<TSelect[]>;
ToListAsync(): Promise<List<TSelect>>;
FirstAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect>;
FirstOrDefaultAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect | undefined>;
LastAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect>;
LastOrDefaultAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect | undefined>;
SingleAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect>;
SingleOrDefaultAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect | undefined>;
CountAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<number>;
AnyAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<boolean>;
AllAsync(predicate: (item: TSelect) => boolean | Promise<boolean>): Promise<boolean>;
MinAsync(): Promise<TSelect>;
MinAsync<TResult>(selector: (item: TSelect) => TResult): Promise<TResult>;
MaxAsync(): Promise<TSelect>;
MaxAsync<TResult>(selector: (item: TSelect) => TResult): Promise<TResult>;
SumAsync(selector?: (item: TSelect) => number): Promise<number>;
AverageAsync(selector?: (item: TSelect) => number): Promise<number>;
LongCountAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<number>;
AggregateAsync<TAccumulate>(seed: TAccumulate, func: (accumulate: TAccumulate, item: TSelect) => Promise<TAccumulate> | TAccumulate): Promise<TAccumulate>;
ContainsAsync(item: TSelect): Promise<boolean>;
ForEachAsync(action: (item: TSelect) => void | Promise<void>): Promise<void>;
ToEnumerable(): Promise<Enumerable<TSelect>>;
ToAsyncEnumerable(): Promise<IAsyncEnumerable<TSelect>>;
AsAsyncEnumerable(): Promise<IAsyncEnumerable<TSelect>>;
AsEnumerable(): Promise<Enumerable<TSelect>>;
ToEnumerableAsync(): Promise<Enumerable<TSelect>>;
}
export declare class PrismaOrderedQueryable<TModel = unknown, TSelect = TModel, TWhereInput = any, TOrderByInput = any, TInclude = any, TSelectInput = any, TCreateInput = any, TUpdateInput = any, TWhereUniqueInput = any> extends PrismaQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput> implements IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput> {
Take(count: number): IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Skip(count: number): IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Distinct<TKey>(keySelector?: (item: TSelect) => TKey): IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
ThenBy(orderBy: TOrderByInput): IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
ThenByDescending(orderBy: TOrderByInput): IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
}
export declare class InMemoryQueryable<TModel = unknown, TSelect = TModel> implements IQueryable<TModel, TSelect, any, any, any, any, any, any, any> {
private data;
constructor(data: TSelect[] | Promise<TSelect[]>);
get Provider(): IQueryProvider;
get Expression(): any;
get ElementType(): any;
WhereFilter(where: any): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
SelectFields<TSelectFields>(select: TSelectFields): IQueryable<TModel, TSelectFields, any, any, any, any, any, any, any>;
Include(include: any): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
OrderBy(orderBy: any): IOrderedQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
SelectMany<TResult>(selector: (item: TSelect) => IQueryable<any, TResult> | IAsyncEnumerable<TResult>): IQueryable<TModel, TResult, any, any, any, any, any, any, any>;
GroupBy<TKey, TElement = TSelect, TResult = IGrouping<TKey, TElement>>(keySelector: (item: TSelect) => TKey, elementSelector?: (item: TSelect) => TElement, resultSelector?: (key: TKey, group: IQueryable<TModel, TElement>) => TResult): IQueryable<TModel, TResult, any, any, any, any, any, any, any>;
Join<TInner, TKey, TResult>(inner: IQueryable<any, TInner>, outerKeySelector: (outer: TSelect) => TKey, innerKeySelector: (inner: TInner) => TKey, resultSelector: (outer: TSelect, inner: TInner) => TResult): IQueryable<TModel, TResult, any, any, any, any, any, any, any>;
Take(count: number): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Skip(count: number): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Distinct<TKey>(keySelector?: (item: TSelect) => TKey): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Union(other: IQueryable<TModel, TSelect>): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Intersect(other: IQueryable<TModel, TSelect>): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Except(other: IQueryable<TModel, TSelect>): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Where: (where: any) => IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Select: <TSelectFields>(select: TSelectFields) => IQueryable<TModel, TSelectFields, any, any, any, any, any, any, any>;
ToArrayAsync(): Promise<TSelect[]>;
ToListAsync(): Promise<List<TSelect>>;
FirstAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect>;
FirstOrDefaultAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect | undefined>;
LastAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect>;
LastOrDefaultAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect | undefined>;
SingleAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect>;
SingleOrDefaultAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect | undefined>;
CountAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<number>;
AnyAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<boolean>;
AllAsync(predicate: (item: TSelect) => boolean | Promise<boolean>): Promise<boolean>;
MinAsync(): Promise<TSelect>;
MinAsync<TResult>(selector: (item: TSelect) => TResult): Promise<TResult>;
MaxAsync(): Promise<TSelect>;
MaxAsync<TResult>(selector: (item: TSelect) => TResult): Promise<TResult>;
SumAsync(selector?: (item: TSelect) => number): Promise<number>;
AverageAsync(selector?: (item: TSelect) => number): Promise<number>;
AggregateAsync<TAccumulate>(seed: TAccumulate, func: (accumulate: TAccumulate, item: TSelect) => Promise<TAccumulate> | TAccumulate): Promise<TAccumulate>;
ContainsAsync(item: TSelect): Promise<boolean>;
ToEnumerable(): Promise<Enumerable<TSelect>>;
ToAsyncEnumerable(): Promise<IAsyncEnumerable<TSelect>>;
AsAsyncEnumerable(): Promise<IAsyncEnumerable<TSelect>>;
AsEnumerable(): Promise<Enumerable<TSelect>>;
ToEnumerableAsync(): Promise<Enumerable<TSelect>>;
ExecuteAsync(): Promise<TSelect[]>;
LongCountAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<number>;
ForEachAsync(action: (item: TSelect) => void | Promise<void>): Promise<void>;
private resolveData;
}