0.12.0 • Published 3 months ago

prisma-dbml-generator v0.12.0

Weekly downloads
3,087
License
MIT
Repository
github
Last release
3 months ago

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

DB Diagram

Getting started

Prismaprisma-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 DescriptionType Default
projectDatabaseTypeProject database type for dbdocsstringnull
projectNameProject name for dbdocsstringnull
projectNoteProject note for dbdocsstringnull
projectNotePathProject note path to a markdown file for dbdocsstringnull
outputOutput directory for the DBML filestring./dbml
outputNameName for the DBML filestringschema.dbml
manyToManyCreate Many-To-Many join tablebooleantrue
mapToDbSchemaUse mapped table namebooleantrue
includeRelationFieldsInclude relation fieldsbooleantrue

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

0.11.0

3 months ago

0.12.0

3 months ago

0.11.1

3 months ago

0.11.0-dev.0

1 year ago

0.10.0

1 year ago

0.10.0-dev.1

1 year ago

0.10.0-dev.0

2 years ago

0.9.1

2 years ago

0.9.0-dev.1

2 years ago

0.9.0

2 years ago

0.9.0-dev.0

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.0-dev.0

3 years ago

0.7.0

3 years ago

0.6.0-dev.2

3 years ago

0.6.0-dev.3

3 years ago

0.6.0-dev.4

3 years ago

0.6.0

3 years ago

0.6.0-dev.1

3 years ago

0.6.0-dev.0

3 years ago

0.5.0-dev.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.4

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago