mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Apply Separate Formatting With A Blank Line as a Prisma TIL
This commit is contained in:
42
prisma/apply-separate-formatting-with-a-blank-line.md
Normal file
42
prisma/apply-separate-formatting-with-a-blank-line.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# Apply Separate Formatting With A Blank Line
|
||||
|
||||
Prisma's CLI includes a `format` command. When run, this will standardize the
|
||||
layout of the `schema.prisma` file. This is variable based on the length of
|
||||
column and attribute names.
|
||||
|
||||
You can exercise some control over the formatting and visually organize the
|
||||
parts of a model by injecting blank lines between sets of statements.
|
||||
|
||||
Here is what a formatted model might look like with no blank lines:
|
||||
|
||||
```prisma
|
||||
model Book {
|
||||
id String @id @default(uuid())
|
||||
title String
|
||||
publicationDate DateTime
|
||||
author Author @relation(fields: [authorId], references: [id])
|
||||
authorId String
|
||||
createdAt DateTime @default(now()) @map(name: "created_at")
|
||||
updatedAt DateTime @updatedAt @map(name: "updated_at")
|
||||
}
|
||||
```
|
||||
|
||||
All the types get aligned based on the longest column name.
|
||||
|
||||
Now, here is what it looks like if I use a blank line to separate all the
|
||||
primary fields from the `createdAt` and `updatedAt`.
|
||||
|
||||
```prisma
|
||||
model Book {
|
||||
id String @id @default(uuid())
|
||||
title String
|
||||
publicationDate DateTime
|
||||
author Author @relation(fields: [authorId], references: [id])
|
||||
authorId String
|
||||
|
||||
createdAt DateTime @default(now()) @map(name: "created_at")
|
||||
updatedAt DateTime @updatedAt @map(name: "updated_at")
|
||||
}
|
||||
```
|
||||
|
||||
Notice how the second block of lines is aligned independent of the first.
|
||||
Reference in New Issue
Block a user