• Stars
    star
    636
  • Rank 70,723 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Prisma DBML Generator

prisma-dbml-generator

Automatically generate a DBML schema from your Prisma Schema.

Build Status Total Downloads npm package License

Updates every time npx prisma generate runs. Use dbdiagram.io to visualize your dbml files as Entity-Relationship Diagram:

DB Diagram

Getting started

Prisma prisma-dbml-generator
>=2.29.0  0.7.0
 <2.29.0  0.6.0
  1. Install this generator:
npm install -D prisma-dbml-generator
  1. Add the generator to the schema.prisma
generator dbml {
  provider = "prisma-dbml-generator"
}
  1. Running npx prisma generate for the following schema.prisma
model User {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  email     String   @unique
  name      String?
  posts     Post[]
  profile   Profile?
  /// user role
  role      Role     @default(USER)
}

/// User profile
model Profile {
  id     Int     @default(autoincrement()) @id
  bio    String?
  user   User    @relation(fields: [userId], references: [id])
  userId Int     @unique
}

model Post {
  id         Int        @id @default(autoincrement())
  title      String     @default("")
  content    String?
  published  Boolean    @default(false)
  author     User?      @relation(fields: [authorId], references: [id])
  authorId   Int?
  categories Category[]
}

model Category {
  id    Int    @id @default(autoincrement())
  name  String
  posts Post[]
}

/// user role
enum Role {
  ADMIN /// allowed to do everything
  USER
}

generates the following schema.dbml to prisma/dbml

//// ------------------------------------------------------
//// THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
//// ------------------------------------------------------

Table User {
  id Int [pk, increment]
  createdAt DateTime [default: `now()`, not null]
  updatedAt DateTime [not null]
  email String [unique, not null]
  name String
  posts Post
  profile Profile
  role Role [not null, default: 'USER', note: 'user role']
}

Table Profile {
  id Int [pk, increment]
  bio String
  user User [not null]
  userId Int [unique, not null]

  Note: 'User profile'
}

Table Post {
  id Int [pk, increment]
  title String [not null, default: '']
  content String
  published Boolean [not null, default: false]
  author User
  authorId Int
  categories Category
}

Table Category {
  id Int [pk, increment]
  name String [not null]
  posts Post
}

Table CategoryToPost {
  categoriesId Int [ref: > Category.id]
  postsId Int [ref: > Post.id]
}

Enum Role {
  ADMIN
  USER
}

Ref: Profile.userId - User.id

Ref: Post.authorId > User.id
  1. Visualize the schema.dbml

Additional Options

Option  Description Type  Default
projectDatabaseType Project database type for dbdocs string null
projectName Project name for dbdocs string null
projectNote Project note for dbdocs string null
projectNotePath Project note path to a markdown file for dbdocs string null
output Output directory for the DBML file string ./dbml
outputName Name for the DBML file string dbml.schema
manyToMany Create Many-To-Many join table boolean true
mapToDbSchema Use mapped table name boolean true
includeRelationFields Include relation fields boolean true

Use additional options in the schema.prisma

generator dbml {
  provider   = "prisma-dbml-generator"
  output     = "../dbml"
  outputName = "awesome.dbml"
  projectName = "Project Name"
  projectDatabaseType = "PostgreSQL"
  projectNote = "Test project description"
}

Development

npm run dev

npm test

Helpful

Prisma Generator

More Repositories

1

nestjs-prisma-starter

Starter template for NestJS 😻 includes GraphQL with Prisma Client, Passport-JWT authentication, Swagger Api and Docker
TypeScript
2,287
star
2

nestjs-prisma

Easy Prisma support for your NestJS application
TypeScript
567
star
3

ngx-tailwind

💨 Simple Angular schematic that initializes Tailwind CSS in your project and adds a custom webpack config to your build process.
TypeScript
128
star
4

nestjs-prisma-docker

Dockerizing a NestJS app with Prisma and PostgreSQL
TypeScript
93
star
5

notiz

Frontend for notiz.dev. Built with Angular and Scully 👋
TypeScript
68
star
6

nestjs-mailer

Send Emails with NestJs
Handlebars
57
star
7

github-action-json-property

☕Simple GitHub Action to read a specified property from a JSON file.
TypeScript
32
star
8

scully-plugins

Scully plugins (fouc, lazy-images, rss, medium-zoom)
TypeScript
22
star
9

nestjs-swagger

NestJS with OpenApi Swagger documentation
TypeScript
16
star
10

floating-form-field-tailwindcss

Floating Form Field using Tailwind CSS
HTML
15
star
11

notiz-api

Notiz Api
Handlebars
9
star
12

cookiemonster

A customizable Cookie Consent Banner for Angular. Built with Tailwind. GDPR & EU ready!
TypeScript
7
star
13

ngx-plausible

Plausible Event directive for Angular
TypeScript
6
star
14

angular-scully-tailwindcss

Jamstack Angular app with Scully and styled with Tailwind CSS
TypeScript
5
star
15

nest-graphql-code-first

Nest Graphql Code First approach
TypeScript
4
star
16

nestjs-prisma-demo

How to query your database using Prisma with Nestjs
TypeScript
4
star
17

ngx-markdoc

Markdoc for Angular
TypeScript
3
star
18

angular-tailwindcss

Learn how to style Angular applications Tailwind CSS
TypeScript
3
star
19

deploy-nestjs-prisma-heroku

Deploy a Nestjs application with Prisma 2 to Heroku and connect to a PostgreSQL database
TypeScript
3
star
20

design

Design for notiz.dev
TypeScript
2
star
21

github-action-template

Simple Typescript GitHub Action Start Template
TypeScript
2
star
22

ngx-gravatar-url

Gravatar Url Pipe for Angular
TypeScript
2
star
23

codegen-angular-nest

TypeScript
1
star