Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

notiz.dev profile imageMarc Stammerjohann
Marc Stammerjohann fornotiz.dev

Posted on • Originally published atnotiz.dev on

     

DBML generator for Prisma

Introducing 🥳Prisma DBML Generatorautomatically generating aDBML schema based on your Prisma Schema.

Simply install the DBML generator

npminstall-D prisma-dbml-generator

Add the generator to yourschema.prisma

generator dbml {  provider = "prisma-dbml-generator"}

Runningnpx prisma generate for the following Prisma schema

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 profilemodel 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  content String?  published Boolean @default(false)  author User? @relation(fields: [authorId], references: [id])  authorId Int?}/// user roleenum Role {  ADMIN /// allowed to do everything  USER}

generates the followingschema.dbml toprisma/dbml

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]  content String  published Boolean [not null, default: false]  author User  authorId Int}Enum Role {  ADMIN  USER}Ref: Profile.userId - User.idRef: Post.authorId > User.id

Copy theschema.dbml content andvisualize it as an Entity-Relationship Diagram:

Entity-Relationship Diagram

You should see this output each time you runnpx prisma generate

$npx prisma generateEnvironment variables loaded from prisma/.env✔ Generated Prisma Client to ./node_modules/@prisma/clientin281ms✔ Generated DBML Schema to ./prisma/dbmlin5msYou can now start using Prisma Clientinyour code:``import{ PrismaClient} from'@prisma/client'// or const{ PrismaClient}= require('@prisma/client')const prisma= new PrismaClient()``Explore the full API: http://pris.ly/d/client

Check out the readme and give it a try with your own Prisma Schema 😎.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

notiz [noˈtiːt͡s] - (german) short, brief, written record

More fromnotiz.dev

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp