giuseppe-trisciuoglio/developer-kit / plugins/developer-kit-typescript/skills/nestjs-drizzle-crud-generator
nestjs-drizzle-crud-generator
VerifiedGenerates complete CRUD modules for NestJS applications with Drizzle ORM. Use when building server-side features in NestJS that require database operations, including creating new entities with full CRUD endpoints, services with Drizzle queries, Zod-validated DTOs, and unit tests. Triggered by requests like "generate a user module", "create a product CRUD", "add a new entity with endpoints", or when setting up database-backed features in NestJS.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 5.3 KB |
| assets/templates/controller-template.ts | script | 1.4 KB |
| assets/templates/dto-template.ts | script | 1003 B |
| assets/templates/module-template.ts | script | 1.2 KB |
| assets/templates/service-template.ts | script | 3.5 KB |
| assets/templates/table-template.ts | script | 709 B |
| assets/templates/test-template.ts | script | 5.1 KB |
| references/field-types.md | markdown | 1.3 KB |
| scripts/generate_crud.py | script | 12.0 KB |
assets/templates/service-template.ts
View on GitHubimport { Injectable, NotFoundException } from '@nestjs/common';
import { Inject } from '@nestjs/common/decorators';
import { eq, isNull, and } from 'drizzle-orm';
import { DrizzleD1Database, DrizzlePgDatabase } from 'drizzle-orm/cloud';
import { {{FeatureName}}Table } from '../schema/{{featureName}}.table';
import {
Create{{FeatureName}}Dto,
Update{{FeatureName}}Dto,
FindAll{{FeatureName}}QueryDto,
} from './dto/{{featureName}}.dto';
export const DrizzleProvider = Symbol('DrizzleProvider');
@Injectable()
export class {{FeatureName}}Service {
private readonly defaultPageSize: number;
private readonly maxPageSize: number;
private readonly includeDeleted: boolean;
constructor(
@Inject(DrizzleProvider)
private readonly db: DrizzleD1Database | DrizzlePgDatabase,
) {
this.defaultPageSize = 10;
this.maxPageSize = 100;
this.includeDeleted = false;
}
async create(dto: Create{{FeatureName}}Dto): Promise<{{FeatureName}}> {
const [created] = await this.db
.insert({{FeatureName}}Table)
.values(dto as any)
.returning();
return created as {{FeatureName}};
}
async findAll(
query: FindAll{{FeatureName}}QueryDto,
): Promise<{ rows: {{FeatureName}}[]; total: number }> {
const { page = 1, limit = this.defaultPageSize, ...filters } = query;
const offset = (page - 1) * Math.min(limit, this.maxPageSize);
const whereConditions = [];
if (!this.includeDeleted) {
whereConditions.push(isNull({{FeatureName}}Table.deletedAt));
}
// Apply filters
for (const [key, value] of Object.entries(filters)) {
if (value !== undefined && value !== null) {
whereConditions.push(
// @ts-ignore - dynamic field access
eq({{FeatureName}}Table[key], value),
);
}
}
const whereClause = and(...whereConditions);
const [rows, countResult] = await Promise.all([
this.db
.select()
.from({{FeatureName}}Table)
.where(whereClause)
.limit(Math.min(limit, this.maxPageSize))
.offset(offset),
this.db
.select({ count: {{FeatureName}}Table.id })
.from({{FeatureName}}Table)
.where(whereClause),
]);
const total = countResult.length;
return {
rows: rows as {{FeatureName}}[],
total,
};
}
async findOne(id: string): Promise<{{FeatureName}} | null> {
const conditions = [eq({{FeatureName}}Table.id, id)];
if (!this.includeDeleted) {
conditions.push(isNull({{FeatureName}}Table.deletedAt));
}
const [result] = await this.db
.select()
.from({{FeatureName}}Table)
.where(and(...conditions));
return (result as {{FeatureName}}) || null;
}
async update(
id: string,
dto: Update{{FeatureName}}Dto,
): Promise<{{FeatureName}}> {
const existing = await this.findOne(id);
if (!existing) {
throw new NotFoundException(`{{FeatureName}} with id ${id} not found`);
}
const [updated] = await this.db
.update({{FeatureName}}Table)
.set({ ...dto, updatedAt: new Date() } as any)
.where(eq({{FeatureName}}Table.id, id))
.returning();
return updated as {{FeatureName}};
}
async remove(id: string): Promise<void> {
const existing = await this.findOne(id);
if (!existing) {
throw new NotFoundException(`{{FeatureName}} with id ${id} not found`);
}
// Soft delete
await this.db
.update({{FeatureName}}Table)
.set({ deletedAt: new Date() } as any)
.where(eq({{FeatureName}}Table.id, id));
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |