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:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1264 TILs and counting..._
|
||||
_1265 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -724,6 +724,7 @@ _1264 TILs and counting..._
|
||||
|
||||
### Prisma
|
||||
|
||||
- [Apply Separate Formatting With A Blank Line](prisma/apply-separate-formatting-with-a-blank-line.md)
|
||||
- [Execute A Raw SQL Query](prisma/execute-a-raw-sql-query.md)
|
||||
- [Grab A Limited Set Of Records](prisma/grab-a-limited-set-of-records.md)
|
||||
- [Specify Alternate Location For Prisma Schema](prisma/specify-alternate-location-for-prisma-schema.md)
|
||||
|
||||
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