Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/arianaprojects/prisma-nestjs-crud-generator

A full CRUD generator for NestJs with Prisma Schema
https://github.com/arianaprojects/prisma-nestjs-crud-generator

backend crud generator nestjs prisma typescript

Last synced: 23 days ago
JSON representation

A full CRUD generator for NestJs with Prisma Schema

Awesome Lists containing this project

README

        





Logo

Prisma Code Generator


A full CRUD generator for NestJs with Prisma Schema


Explore the docs »




View Demo
·
Report Bug
·
Request Feature


Table of Contents



  1. About The Project



  2. Getting Started


  3. Example

  4. Roadmap

  5. Contributing

  6. License

  7. Contact

## About The Project

[![Product Name Screen Shot][product-screenshot]](https://example.com)

There are many great Generators available on GitHub for Prisma Schema; however we wanted a fully automatic and complete generator which is compatible with [NestJs](https://nestjs.com/) and we didn't find. So we created this advanced generator.

Of course, no one Generators will serve all projects since your needs may be different. So We'll be adding more in the near future. You may also suggest changes by forking this repo, creating a pull request, or opening an issue. Thanks to all the people who have contributed to expanding this template!

(back to top)

### Built With

This project is built on top of [Next.js](https://nextjs.org/) Framework Template, which is fully configured by Our Team at [Ariana Company](https://www.arianagermany.com/). You need at least the following packages and libraries for this Generator, which we used in our NestJs template.

- [Prisma](https://prisma.io/)
- [class-transformer](https://github.com/typestack/class-transformer)
- [class-validator](https://github.com/typestack/class-validator)
- [@nestjs/swagger](https://github.com/nestjs/swagger)
- [@nestjs/common](https://github.com/nestjs/common)

(back to top)

## Getting Started

This section will learn how to use our generator with Prisma and NestJs. We will not show how to install and configure NestJs, and we assume that you know NestJs and Prisma well

### Installation

Simply install the Prisma Code Generator

- npm
```sh
npm i @ariana-germany/prisma-code-generator -D
yarn add @ariana-germany/prisma-code-generator -D
```

### Configuration

After installation, you should add our configuration to your Prisma.schema File.

```TS
generator Prisma_Code_Generator {
provider = "Prisma_Code_Generator"
output = "../gen"
}
```

Output path is relative to the path of the Prisma.schema File and should be an folder.

> **_WARNING_**: Generator will overwrite the folders with the same name as models in the output path.

(back to top)

## Generation

The Prisma command line interface (CLI) is the primary way to interact with our Generator.

for example:

```sh
npx prisma generate
```

(back to top)

## Usage

Now, your CRUD is generated. For using this generated CRUD you should import each of the Module's Model in to your main module. In our case is app.module.ts.

# Example

Now, your CRUD is generated. For using this generated CRUD you should import each of the Module's Model in to your main module. In our case is app.module.ts.

## Prisma.schema

```Prisma

generator prismaCodeGenerator {
provider = "prisma-code-generator"
output = "../gen"
}

generator client {
provider = "prisma-client-js"

}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id Int @id @default(autoincrement())
email String @unique
name String?
Address Address[]
}

model Address {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
User User? @relation(fields: [userId], references: [id])
Tax Tax[]
axId Int?
line1 String
line2 String
line3 String
city String
zipcode String
userId Int?
}

model Tax {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime?
Address Address? @relation(fields: [addressId], references: [id])
addressId Int?
}
```

## Folder sctructure

```
📦gen
┣ 📂address
┃ ┣ 📜address.controller.ts
┃ ┣ 📜address.dto.ts
┃ ┣ 📜address.entity.ts
┃ ┣ 📜address.module.ts
┃ ┗ 📜address.service.ts
┣ 📂tax
┃ ┣ 📜tax.controller.ts
┃ ┣ 📜tax.dto.ts
┃ ┣ 📜tax.entity.ts
┃ ┣ 📜tax.module.ts
┃ ┗ 📜tax.service.ts
┗ 📂user
┃ ┣ 📜user.controller.ts
┃ ┣ 📜user.dto.ts
┃ ┣ 📜user.entity.ts
┃ ┣ 📜user.module.ts
┃ ┗ 📜user.service.ts
```

app.module.ts

```TS
@Module({
imports: [
...
AddressModule,
TaxModule,
UserModule,
...
],
controllers: [
...
],
providers: [
...
],
})
export class AppModule implements NestModule {
...
}

```

(back to top)

## Roadmap

- [x] initial
- [x] soft Delete
- [ ] Add Additional Templates w/ Examples
- [ ] Refactoring
- [ ] MySQL
- [ ] MongoDB

See the [open issues](https://github.com/ariana-germany/prisma-code-generator/issues) for a full list of proposed features (and known issues).

(back to top)

## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

(back to top)

## License

Distributed under the Apache License Version 2.0 License. See `LICENSE.txt` for more information.

(back to top)

## Contact

Shayan - [email protected] - [email protected]

(back to top)