@arianaprojects/prisma-nestjs-crud-generator
v0.4.12
Published
code generator from Prisma schema
Downloads
105
Maintainers
Readme
About The Project
![Product Name Screen Shot][product-screenshot]
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 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!
Built With
This project is built on top of Next.js Framework Template, which is fully configured by Our Team at Ariana Company. You need at least the following packages and libraries for this Generator, which we used in our NestJs template.
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
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.
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.
Generation
The Prisma command line interface (CLI) is the primary way to interact with our Generator.
for example:
npx prisma generate
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
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
@Module({
imports: [
...
AddressModule,
TaxModule,
UserModule,
...
],
controllers: [
...
],
providers: [
...
],
})
export class AppModule implements NestModule {
...
}
Roadmap
- [x] initial
- [x] soft Delete
- [ ] Add Additional Templates w/ Examples
- [ ] Refactoring
- [ ] MySQL
- [ ] MongoDB
See the open issues for a full list of proposed features (and known issues).
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the Apache License Version 2.0 License. See LICENSE.txt
for more information.
Contact
Shayan - [email protected] - [email protected]