Type
Types provide a way to define complex data structures that are not backed by a database table. They server two purposes:
- Types can be used as mixins to contain common fields and attributes shared by multiple models.
- Types can be used to define strongly typed JSON fields in models.
Syntax​
type NAME {
FIELD*
ATTRIBUTE*
}
-
NAME:
Name of the model. Needs to be unique in the entire model. Must be a valid identifier.
-
FIELD:
Arbitrary number of fields. See Field for details.
-
ATTRIBUTE:
Arbitrary number of attributes. See Attribute for details.
Example​
type Profile {
age Int
gender String
}
type CommonFields {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model User with CommonFields {
email String @unique
name String
profile Profile? @json
}