You can access the user_type enum in your application code like this:
import {user_type } from "@prisma/client";
let foo: user_type = "superadmin";
// use like any other type/enum
How you plan to connect this to the client-side or send it there is up to you. Typically Prisma types reside in the server-side of your code, not the client-side, so it might be difficult to import prisma types in your client code directly.
This is how Prisma defines the user_type enum under the hood.
// file: node_modules/.prisma/client/index.d.ts
export const user_type: {
superadmin: 'superadmin',
admin: 'admin',
user: 'user'
};
You could just copy and paste this into your client-side code if you like.
Answer from Tasin Ishmam on Stack OverflowYou can access the user_type enum in your application code like this:
import {user_type } from "@prisma/client";
let foo: user_type = "superadmin";
// use like any other type/enum
How you plan to connect this to the client-side or send it there is up to you. Typically Prisma types reside in the server-side of your code, not the client-side, so it might be difficult to import prisma types in your client code directly.
This is how Prisma defines the user_type enum under the hood.
// file: node_modules/.prisma/client/index.d.ts
export const user_type: {
superadmin: 'superadmin',
admin: 'admin',
user: 'user'
};
You could just copy and paste this into your client-side code if you like.
When you generate Prisma Client, it generates TypeScript interfaces for your models and enum types.
you can do
import { PrismaClient, user_type } from '@prisma/client'
and this will give you the user_type types declarations
Specify value for Enum
Enum with custom value
Missing generated Enum in typescript definition when Enum isn't used in Prisma table
Recommended Enum usage with Prisma and Zod
Has anyone worked with Prisma? How could I tell a model that if it doesn't write the Role field, i by default will be "Customer"?
I get an alert if I do it like this:
: Error validating: This line is not a valid field or attribute definition.
In another ORM like Sequalize it's something like this:
role: {
allowNull: false,
type: DataTypes.STRING,
defaultValue: 'customer'
}This is all the model in Sequalize
const UserSchema = {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: DataTypes.INTEGER
},
email: {
allowNull: false,
type: DataTypes.STRING,
unique: true,
},
password: {
allowNull: false,
type: DataTypes.STRING
},
role: {
allowNull: false,
type: DataTypes.STRING,
defaultValue: 'customer'
},
createdAt: {
allowNull: false,
type: DataTypes.DATE,
field: 'create_at',
defaultValue: Sequelize.NOW
}
}