@algochad/prisma-core
v1.2.3
Published
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
Maintainers
Readme
@algochad/prisma-core
A powerful NestJS library that brings Entity Framework Core-like operations to Prisma ORM and GraphQL, enhanced with C# LINQ-style data manipulation capabilities. This library provides a unified, type-safe API for database interactions while offering advanced query building, data transformation, and performance optimization features.
🚀 Features
- 🏗️ EF-Core-like Operations: Intuitive query building and data manipulation using Prisma ORM
- 🌐 GraphQL Data Source Support: Full LINQ-style queries with GraphQL APIs (requires schema matching)
- 🔗 LINQ Operations: Basic port of C# LINQ operations for advanced data queries and transformations
- 🔧 Extensible API: Unified, type-safe API for seamless database and GraphQL interactions
- ⚡ Performance Optimized: Built-in benchmarking and performance optimization tools
- 🏢 NestJS Integration: Native integration designed specifically for NestJS applications
- 📊 Universal Repository Pattern: Dynamic model access with full type safety across data sources
- 🔄 Transaction Support: Comprehensive transaction management capabilities (Prisma ORM)
📚 Quick Navigation
🚀 Getting Started
- 📦 Installation Guide - Set up the library in your project
- 🛠️ Quick Setup Guide - Complete setup with examples
- ⭐ Quick Start Patterns - Most commonly used Select & OrderBy patterns
📖 Core Documentation
- 📖 Usage Guide - Basic query operations and patterns
- 🔗 LINQ Operations - Synchronous and asynchronous LINQ operations
- 🏛️ Universal Repository Pattern - Three ways to access models
- ⚡ Performance Benchmarks - Comprehensive benchmarking and optimization guide
📚 Reference & Help
- 🛠️ API Reference - Complete API documentation
- 🔧 Troubleshooting - Common issues and solutions
- 📚 Examples & Tutorials - Real-world examples and tutorials
🤝 Community
- 🤝 Contributing - How to contribute to the project
- 📄 License - MIT License details
⚡ Quick Example
// Simple query with field selection and sorting
const results = await repository.test
.Where({ isActive: true })
.Select({
id: true,
name: true,
description: true,
})
.OrderBy({ name: 'asc' })
.ToArray();
// LINQ-style transformations
const transformed = await repository.test
.Where({ isActive: true })
.ToEnumerable()
.Where((test) => test.description != null)
.Select((test) => ({
id: test.id,
displayName: test.name.toUpperCase(),
summary: `${test.name}: ${test.description}`,
}))
.OrderBy((item) => item.displayName)
.ToArray();
// Async performance optimization for large datasets
const optimized = await AsyncEnumerable.from(largeDataset)
.Where(async (item) => await validateAsync(item))
.Select(async (item) => await transformAsync(item))
.ToArrayAsync();📊 Performance Highlights
- ⚡ 76% Performance Improvement with AsyncEnumerable for complex operations
- 💾 7% Memory Efficiency gains with async processing
- 🎯 2.8x Faster Sorting operations with async implementations
- 📈 Scales to 100K+ items with optimized processing
When to Use What
| Operation Type | Dataset Size | Recommendation | Reason |
| ----------------------- | ------------- | ----------------- | --------------------------- |
| Simple filtering | < 1,000 items | Enumerable | Lower overhead |
| Complex transformations | > 1,000 items | AsyncEnumerable | Parallel processing |
| Database queries | Any size | AsQueryable() | Database-level optimization |
| Sorting operations | > 1,000 items | AsyncEnumerable | 2.8x performance gain |
🏗️ Repository Setup
@Injectable()
export class AppRepository extends PrismaRepository {
constructor(databaseService: PrismaCoreService) {
super(databaseService);
}
// Typed accessor for User model
get user(): PrismaUnifiedBuilder<User> {
return this.model<User>('user') as any;
}
// Typed accessor for Post model
get post(): PrismaUnifiedBuilder<Post> {
return this.model<Post>('post') as any;
}
}🔗 Links and Resources
- 📖 Full Documentation: Complete Documentation
- 📦 NPM Package: @algochad/prisma-core
- 🐛 GitHub Issues: Report Issues
- 💬 GitHub Discussions: Community Discussions
- 🏗️ Prisma Documentation: Prisma Docs
- 🏢 NestJS Documentation: NestJS Docs
Made with ❤️ for the NestJS and Prisma community
Star ⭐ this project if you find it helpful!
