From 1b99a78cf482a4ca7e882a5d7a7033bbb0ea58e5 Mon Sep 17 00:00:00 2001 From: Yiming Cao Date: Fri, 4 Nov 2022 10:37:42 +0800 Subject: [PATCH] chore: add @password @omit field attributes documentation --- .../learning-the-zmodel-language.md | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/docs/get-started/learning-the-zmodel-language.md b/docs/get-started/learning-the-zmodel-language.md index d1793e306..43a55bb9b 100644 --- a/docs/get-started/learning-the-zmodel-language.md +++ b/docs/get-started/learning-the-zmodel-language.md @@ -89,7 +89,39 @@ model Post { } ``` -Please refer to [Prisma's documentation](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#attributes) for an exhaustive list of attributes and functions. +ZenStack inherits most attributes and functions from Prisma, and added a number of new ones: + +- `@password` + + A field attribute that marks a field as a password. Before storing such a field, ZenStack hashes its value with [bcryptjs](https://github.com/dcodeIO/bcrypt.js), with a default salt length of 12. + + You can override the default setting with the `saltLength` or `salt` named parameters, like: + +```prisma +model User { + password String @password(saltLength: 16) +} + +model User { + password String @password(salt: "mysalt") +} +``` + +If both `saltLength` and `salt` parameters are provided, `salt` is used. + +- `@omit` + + A field attribute that marks a field to be excluded when model entities are read from the generated service. This is often used to prevent sensitive information from being returned to the front-end code (e.g., password, even hashed). + + E.g.: + +```prisma +model User { + password String @password @omit +} +``` + +For attributes and functions inherited from Prisma, please refer to [Prisma's documentation](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#attributes) for details. ## Relations