UNPKG

@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

189 lines 6.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GraphQLUnifiedBuilder = void 0; const graphql_query_builder_1 = require("./graphql-query-builder"); const graphql_mutation_builder_1 = require("./graphql-mutation-builder"); const graphql_queryable_1 = require("../../collections/graphql/graphql-queryable"); class GraphQLUnifiedBuilder { queryBuilder; mutationBuilder; constructor(genqlClient, queryOperationName, mutationOperationNames, operationType = 'query') { this.queryBuilder = new graphql_query_builder_1.GraphQLQueryBuilder(genqlClient, queryOperationName, operationType); this.mutationBuilder = new graphql_mutation_builder_1.GraphQLMutationBuilder(genqlClient, mutationOperationNames); } factory = () => new GraphQLUnifiedBuilder(this.queryBuilder['genqlClient'], this.queryBuilder['operationName'], this.mutationBuilder['operationNames'], this.queryBuilder['operationType']); Where(where) { this.queryBuilder.Where(where); return this; } Select(select) { this.queryBuilder.Select(select); return this; } Include(include) { this.queryBuilder.Include(include); return this; } OrderBy(orderBy) { this.queryBuilder.OrderBy(orderBy); return this; } Take(n) { this.queryBuilder.Take(n); return this; } Skip(n) { this.queryBuilder.Skip(n); return this; } async ToEnumerable() { return await this.queryBuilder.ToEnumerable(); } async ToArray() { return await this.queryBuilder.ToArray(); } async First() { return await this.queryBuilder.First(); } async FirstOrDefault() { return await this.queryBuilder.FirstOrDefault(); } async Single() { return await this.queryBuilder.Single(); } async Count() { return await this.queryBuilder.Count(); } async Exists() { return await this.queryBuilder.Exists(); } async Any() { return await this.queryBuilder.Any(); } async Min(field) { return await this.queryBuilder.Min(field); } async Max(field) { return await this.queryBuilder.Max(field); } async Sum(field) { return await this.queryBuilder.Sum(field); } async Avg(field) { return await this.queryBuilder.Avg(field); } Project(selector) { return this.queryBuilder.Project(selector); } async Create(data) { return this.mutationBuilder.Create(data); } async CreateMany(data) { return this.mutationBuilder.CreateMany(data); } async Update(where, data) { return this.mutationBuilder.Update(where, data); } async UpdateMany(where, data) { return this.mutationBuilder.UpdateMany(where, data); } async Upsert(where, create, update) { return this.mutationBuilder.Upsert(where, create, update); } async Delete(where) { return this.mutationBuilder.Delete(where); } async DeleteMany(where) { return this.mutationBuilder.DeleteMany(where); } async BulkUpsert(records) { return this.mutationBuilder.BulkUpsert(records); } async ExecuteCustomMutation(operationName, args, selection = true) { return this.mutationBuilder.ExecuteCustomMutation(operationName, args, selection); } async ExecuteBatch(mutations) { return this.mutationBuilder.ExecuteBatch(mutations); } AsQueryable() { const genqlClient = this.queryBuilder['genqlClient']; const operationName = this.queryBuilder['operationName']; const operationType = this.queryBuilder['operationType']; const provider = new graphql_queryable_1.GraphQLQueryProvider(genqlClient, operationName, operationType); const expression = this.queryBuilder.Expression; return new graphql_queryable_1.GraphQLQueryable(provider, expression); } ContextFactory() { return this.factory(); } Fresh() { return this.factory(); } New() { return this.Fresh(); } async *Subscribe() { for await (const item of this.queryBuilder.Subscribe()) { yield item; } } AsAsyncEnumerable() { return this.queryBuilder.AsAsyncEnumerable(); } WhereEquals(field, value) { const whereCondition = { [field]: value }; return this.Where(whereCondition); } WhereContains(field, value) { const whereCondition = { [field]: { contains: value } }; return this.Where(whereCondition); } WhereStartsWith(field, value) { const whereCondition = { [field]: { startsWith: value } }; return this.Where(whereCondition); } WhereEndsWith(field, value) { const whereCondition = { [field]: { endsWith: value } }; return this.Where(whereCondition); } WhereIn(field, values) { const whereCondition = { [field]: { in: values } }; return this.Where(whereCondition); } WhereNotIn(field, values) { const whereCondition = { [field]: { notIn: values } }; return this.Where(whereCondition); } WhereGreaterThan(field, value) { const whereCondition = { [field]: { gt: value } }; return this.Where(whereCondition); } WhereGreaterThanOrEqual(field, value) { const whereCondition = { [field]: { gte: value } }; return this.Where(whereCondition); } WhereLessThan(field, value) { const whereCondition = { [field]: { lt: value } }; return this.Where(whereCondition); } WhereLessThanOrEqual(field, value) { const whereCondition = { [field]: { lte: value } }; return this.Where(whereCondition); } WhereBetween(field, min, max) { const whereCondition = { AND: [{ [field]: { gte: min } }, { [field]: { lte: max } }], }; return this.Where(whereCondition); } WhereNull(field) { const whereCondition = { [field]: null }; return this.Where(whereCondition); } WhereNotNull(field) { const whereCondition = { [field]: { not: null } }; return this.Where(whereCondition); } } exports.GraphQLUnifiedBuilder = GraphQLUnifiedBuilder; //# sourceMappingURL=graphql-unified-builder.js.map