3.2.2 • Published 7 months ago

prisma-repository-generator v3.2.2

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

🚀 Prisma Repository Generator

🌟 Description

Prisma Repository Generator is a powerful utility designed to automate the creation of repository files based on your Prisma models. It eliminates repetitive boilerplate code by generating common CRUD operations for database interactions, which improves consistency, scalability, and maintainability across your applications.

Instead of manually generating repetitive database logic code for each Prisma model, it generates reusable repository classes with standard methods. Developers can focus on application development instead of tedious CRUD generation.

📌 NOTE\ This generator currently only works with TypeScript. Support for additional languages ​​may be added in the future.

📥 Prerequisites

Before using the Prisma Repository Generator, make sure you have the necessary dependencies and tools ready:

1. Install Prisma Client

npm install @prisma/client

2. Install Prisma Repository Generator

npm install prisma-repository-generator

⚙️ Setup Instructions

Follow the steps below to set up Prisma and generate repositories:

1. Set Up Prisma Database Schema

Make sure you define the Prisma schema in prisma/schema.prisma. Here is an example of a schema you can use:

model User {
  id    Int    @id @default(autoincrement())
  name  String
  email String @unique
}

model Post {
  id      Int    @id @default(autoincrement())
  title   String
  content String
  userId  Int
}

2. Run Migrations

After defining your schema, apply it to the database using the following command:

npx prisma migrate dev --name init

This will create the necessary database structure.

⚠️ IMPORTANT\ Make sure you run migrations (npx prisma migrate dev --name init) before using the repository generator to avoid runtime issues.

3. Generate Repositories

Import and execute the repository generator with the following:

import { generateRepositories } from 'prisma-repository-generator';

generateRepositories().catch((err) => {
    console.error("Error generating repositories:", err.message);
});

This will create repository files based on your Prisma models.

✂️ Shortcut

To simplify and speed up the repository generation process without needing to write extra code, use the following command directly from your terminal:

npx prisma-repository-generator

This command will automatically run the Prisma Repository Generator. You don’t need to import or write additional code in your project. Just run this command in your project directory after ensuring Prisma is set up correctly.

⚠️ IMPORTANT\ Make sure you run migrations (npx prisma migrate dev --name init) before using this shortcut to avoid to avoid runtime issues.

✅Features

  • findUnique : Retrieve a single record by unique identifier.
  • findUniqueOrThrow : Retrieve a single record or throw an error if it doesn't exist.
  • findFirst : Fetch the first matching record with optional filtering and sorting.
  • findFirstOrThrow : Same as findFirst, but throws an error if no record is found.
  • findMany : Fetch multiple records with filtering, pagination, and cursor support.
  • create : Insert a single record.
  • update : Update a record by unique identifier.
  • upsert : Insert or update a record based on a unique condition.
  • delete : Delete a single record by unique identifier.
  • createMany : Insert multiple records at once.
  • updateMany : Update multiple records with specific conditions.
  • deleteMany : Delete multiple records based on optional filtering.
  • count : Count records with optional filtering.
  • aggregate : Perform aggregation queries.

💰Support Me

PayPal Saweria Trakteer

3.2.2

7 months ago

3.2.1

7 months ago

3.2.0

7 months ago

3.1.7

7 months ago

3.1.6

7 months ago

3.1.5

7 months ago

3.1.4

7 months ago

3.1.3

7 months ago

3.1.2

7 months ago

3.1.1

7 months ago

3.1.0

7 months ago

3.0.6

7 months ago

3.0.5

7 months ago

3.0.4

7 months ago

3.0.3

7 months ago

3.0.2

7 months ago

3.0.1

7 months ago

3.0.0

7 months ago

2.0.1

7 months ago

2.0.0

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago