GithubHelp home page GithubHelp logo

areindl / prisma-dbml-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from notiz-dev/prisma-dbml-generator

0.0 0.0 0.0 938 KB

Prisma DBML Generator

License: MIT License

JavaScript 0.49% TypeScript 99.51%

prisma-dbml-generator's Introduction

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 schema.dbml
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

prisma-dbml-generator's People

Contributors

marcjulian avatar garygrossgarten avatar williamluke4 avatar pabloszx avatar jaimeloeuf avatar jon-lewis avatar maxmousse avatar ssukienn avatar doflo-dfa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.