Backend Boilerplates
javascript
Intermediate
Prisma Soft Delete Middleware
Globally intercept Prisma queries to filter soft-deleted records transparently.
javascript
module.exports = (prisma) => {
const reads = ['findUnique','findFirst','findMany'];
prisma.$use(async (params, next) => {
if (reads.includes(params.action)) {
params.args = params.args || {};
params.args.where = { ...params.args.where, deletedAt: null };
}
if (params.action === 'delete') {
params.action = 'update';
params.args.data = { deletedAt: new Date() };
}
return next(params);
});
};
Prerequisites
- @prisma/client >= 4
Pro Tips
- → Add DB index on deletedAt.
- → Override for admin routes that need deleted records.
Commercial Licensing
Acquire a production access token or template license for enterprise deployment.
Module Info
- Language
- javascript
- Level
- Intermediate
- Read time
- 3 min
- Published
- Jul 2024
- License
- Commercial License
Newsletter
New modules every week, directly to your inbox.
Similar Modules
Laravel Artisan Seeder Command
Artisan command to re-seed production data with a confirmation prompt.
php
·
Intermediate
CSV to PostgreSQL Bulk Loader
Stream a large CSV directly into PostgreSQL using COPY for maximum throughput.
python
·
Intermediate
Go Event Sourcing Store
Minimal append-only event store in Go backed by a Postgres table.
go
·
Advanced