Skip to content

Commit

Permalink
v1.1.4 - issues fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
joydip007x committed Oct 10, 2023
1 parent d34db41 commit d2bb6bb
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 825 deletions.
208 changes: 7 additions & 201 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
[![Tests](https://github.com/joydip007x/Prisma-MultiSchema/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/joydip007x/Prisma-MultiSchema/actions/workflows/tests.yml) [![NPM](https://img.shields.io/github/languages/code-size/joydip007x/Prisma-MultiSchema?label=size)](https://github.com/joydip007x/Prisma-MultiSchema)
[![Snyk](https://github.com/joydip007x/Prisma-MultiSchema/actions/workflows/snyk.yml/badge.svg?branch=main)](https://github.com/joydip007x/Prisma-MultiSchema/actions/workflows/snyk.yml)


<p align="center">
<img media="(prefers-color-scheme: light)" src="logo/logoDark.gif#gh-dark-mode-only" />
<img media="(prefers-color-scheme: dark)" src="logo/logoLight.gif#gh-light-mode-only" />

<img src="https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExOTU5NmYyYzI0NGU2NTI4YTUyY2ZjN2IyZjBiY2QzYWIwZmRjMDQ2MCZlcD12MV9pbnRlcm5hbF9naWZzX2dpZklkJmN0PWc/cNWy8aU7WT0V2hwiUy/giphy.gif">

</p>

# Prisma: MultiSchema [![NPM](https://badgen.net/npm/types/prisma-multischema)](https://www.npmjs.com/package/prisma-multischema)
Expand All @@ -17,211 +17,17 @@ For Multiple files inter-relation you can import schemas , to manage the relati
Built using TypeScript to for ES Module and CommonJS (CJS),
to Unify Multiple Structured Schemas of [Prisma-ORM](https://www.prisma.io/)

<details open >
<summary >

### Installation
</summary>
<p align="center">

# Installation
```
npm i prisma-multischema
```
```
yarn add prisma-multischema
```
> **Note** Using **VS Code** ? Install Recommended VsCode Extensions from [Dependencies (optional)](https://github.com/joydip007x/Prisma-MultiSchema#dependencies-optional)
</p>
</details>
<details close >
<summary >

### Usage
</summary>
<p align="center">

- #### How to Use Tutorial : 📚[MediumBlog](https://medium.com/@joydip007x/how-to-use-multiple-schema-in-prisma-40cc6b6f8d9c) || ✨[YT Link](https://youtu.be/4GOuJLvGVko)
- Place all your schemas in `ProjectRoot/prisma/subschemas` Folder.<br>
Like this :
```st
project_root
├───node_modules
├───prisma
│ ├───subschemas <<<-----Place all your Schemas here
│ │ ├───type
│ │ │ └───user.types.prisma
│ │ │ └───bookmark.types.prisma
│ │ └───user
│ │ │ └───userData.prisma
│ │ │ └───validity.prisma
│ │ ├───anything-you-want.prisma
│ │ ├───base.prisma
| | └───...
│ └───schema.prisma <-- will be Auto-Generated
├───src
│ └───...
├───package.json
└───.gitignore
```
>For Clearer View : [Image](https://i.ibb.co/JnyRhxT/oie-eg-Dr9-Y4ksb-NU.png)


- Run in Terminal
```bash
npx prisma-multischema
```

</p>
</details>

<details close >
<summary >

### Project Demonstration
</summary>
<p align="center">

working example is available below -
- <b>JavaScript</b> : [Prisma-MultiSchema-JS-Example](https://github.com/joydip007x/Prisma-MultiSchema-JS-Example)
- <b>TypeScript</b> : [Prisma-MultiSchema-TS-Example](https://github.com/joydip007x/Prisma-MultiSchema-TS-Example)
</p>
</details>
<details close >
<summary >

### Example
</summary>
<p align="center">

Let's go with two schemas <b>User</b> and <b>Bookmark</b> on different files ,where the relation is -
- A User can have many bookmarks
- Each bookmark has an userId field
><b>base.prisma</b> [ root/prisma/subschemas/base.prisma ]
```prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mongodb"
url = env("PRISMA_DATABASE_URL")
}
```
><b>user.prisma</b> [ root/prisma/subschemas/User/user.prisma ]
```Prisma
import { Bookmark } from "..\Bookmark\bookmark"
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
Bookmark Bookmark[]
}
//MongoDB model IDs in prisma -must have a @map("_id")
//https://www.prisma.io/docs/concepts/components/prisma-schema
```
><b>bookmark.prisma</b> [ root/prisma/subschemas/Bookmark/bookmark.prisma ]
```Prisma
import { User } from "..\User\user"
model Bookmark {
id String @id @db.ObjectId @default(auto()) @map("_id")
title String
user User @relation(fields: [userId], references: [id])
userId String @db.ObjectId
}
```
>Generated <b>schema.prisma</b> [root/prisma/schema.prisma]</br>
> after Running `npx prisma-multischema`
```Prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mongodb"
url = env("PRISMA_DATABASE_URL")
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
Bookmark Bookmark[]
}
model Bookmark {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
user User @relation(fields: [userId], references: [id])
userId String @db.ObjectId
}
```
>https://www.prisma.io/docs
</p>
</details>
<details >
<summary >
### Additional
</summary>
<p align="center">
- prisma schema files starting with header `//#exclude` will be excluded in final schema
- Executing `npx prisma-multischema` will
- <b>Automatically run</b> : `npx prisma generate`
<br>So, You don't need to update `@prisma/client` manually, each time the schema updates
- <b>Automatically run</b> : `npx prisma format`
<br> because, Everyone likes clean code

- Add `npx prisma-multischema` command as a prefix to your <b>start</b> script in package.json.
```json
{
"name": "my-app",
"version": "1.0.0",
"scripts": {
"unify": "npx prisma-multischema",
"start": "npm run unify && node index.js",
...
}
}
```
<br>Now it will run & regenerate Main Schema everytime the project starts.
<br></p>
</details>
<details close >
<summary >

### Dependencies (optional)
</summary>
<p align="center">

To use <b>prisma import</b> feature : (<i>if you are using VS code, its better to use these</i>)<br>
<br>
- Install [prisma-import](https://marketplace.visualstudio.com/items?itemName=ajmnz.prisma-import) Extension (for VS code)

- <b>Disable</b> Official [prisma](https://marketplace.visualstudio.com/items?itemName=Prisma.prisma) Extension (for VS code)
---

>These are <b>Optional Dependencies</b>, If you can maintain multiple *.prisma schemas without <b>TYPO</b> ,you can ignore these.
</p>
</details>
<details close >
<summary >

### To-do's
</summary>
<p align="center">

- Add Support for keeping prisma's in different folder and aggregate them ( like `root/src/auth/auth.prisma `)
# [Documentation](https://github.com/joydip007x/Prisma-MultiSchema#readme) : [![NPM]( https://img.shields.io/badge/Github-joydip007x%2Fprisma--multischema-blue)](https://github.com/joydip007x/Prisma-MultiSchema#readme)

- Add Command Flags
- ~~Handle/Remove `" Error validating datasource db: "` Warning~~ Fixed

</p>
</details>

#### Authors - [@joydip007x](https://www.github.com/joydip007x)
## Authors - [@joydip007x](https://www.github.com/joydip007x)
17 changes: 7 additions & 10 deletions bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ function sleep(ms){
async function commands(){

await prismaUnifier();
await sleep(300);
console.log("⏲","\x1b[33m","Wait ! Running: ","\x1b[1m","npx prisma generate","\x1b[0m");
const gen= exec('npx prisma generate')
const p=setTimeout(()=>{
exec('npx prisma format')
console.log(' Run:',"\x1b[1m","\x1b[34m","npx prisma studio","\x1b[0m","to inspect your database");
console.log(" ✅ Generated","\x1b[32m","Prisma Client ","\x1b[0m","Reference: https://pris.ly/d/client ");
console.log(" Start Using :"," import { PrismaClient } from '@prisma/client'\n",
" const prisma = new PrismaClient()");
console.log("⏲","\x1b[33m","Wait ! Running: ","\x1b[1m","npx prisma generate & npx prisma format","\x1b[0m");
exec('npx prisma generate')
exec('npx prisma format')
console.log(' Run:',"\x1b[1m","\x1b[34m","npx prisma studio","\x1b[0m","to inspect your database");
console.log(" ✅ Generated","\x1b[32m","Prisma Client ","\x1b[0m","Reference: https://pris.ly/d/client ");
console.log("\x1b[32m","Leave a star⭐:","\x1b[0m","https://github.com/joydip007x/Prisma-MultiSchema",". It helps a lot. ",);

},700);

}
commands();

Expand Down
Loading

0 comments on commit d2bb6bb

Please sign in to comment.