1.0.4 ⢠Published 5 months ago
prisma-case-builder v1.0.4
Prisma CASE Query Builder ā”ļø
A simple and lightweight CASE query builder for Prisma, making raw SQL queries easier and more readable.
š Features
ā
Fluent, chainable API
ā
Type-safe column suggestions
ā
Works seamlessly with Prisma
š¦ Installation
npm install prisma-case-builder
š ļø Usage
const result = await prisma.user
.case("role")
.when({ column: "age", operator: ">=", value: 18 })
.then("Adult")
.when({ column: "age", operator: "<", value: 18 })
.then("Go home! :P")
.else("Unknown")
.toExec();
š§ Setup
To integrate the CASE query builder with Prisma, extend your PrismaClient
:
import { PrismaClient } from "@prisma/client";
import { CaseBuilder } from "prisma-case-builder";
export const prisma = new PrismaClient().$extends({
model: {
$allModels: {
case<T>(this: T, field: string) {
return new CaseBuilder<T>(this, prisma).case(field);
},
},
},
});
š License
MIT
Enjoy using Prisma CASE Query Builder? Give it a ā on GitHub! š