Skip to content

A lightweight and simple CASE query builder for Prisma ⚡️

Notifications You must be signed in to change notification settings

caushcani/prismacase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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! 🚀

About

A lightweight and simple CASE query builder for Prisma ⚡️

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published