diff --git a/README.md b/README.md index a832c0a..05ec151 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/prisma/apply-separate-formatting-with-a-blank-line.md b/prisma/apply-separate-formatting-with-a-blank-line.md new file mode 100644 index 0000000..16e1ae8 --- /dev/null +++ b/prisma/apply-separate-formatting-with-a-blank-line.md @@ -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.