Pieter
08/26/2021, 12:56 PMRyan
08/26/2021, 12:58 PMprisma._dmmf
should give you the model names.Ryan
08/26/2021, 12:58 PMprisma
is the PrismaClient
instance.Pieter
08/26/2021, 12:58 PMPieter
08/26/2021, 12:59 PMRyan
08/26/2021, 12:59 PMPieter
08/26/2021, 12:59 PMPieter
08/26/2021, 1:00 PMRyan
08/26/2021, 1:00 PM// @ts-ignore
in this caseRyan
08/26/2021, 1:00 PMPieter
08/26/2021, 1:00 PMPieter
08/26/2021, 1:00 PMPieter
08/26/2021, 1:01 PMRyan
08/26/2021, 1:01 PMPieter
08/26/2021, 1:02 PMPieter
08/26/2021, 1:02 PMconst user = prisma.users.findFirst()
console.log(Object.keys(user))
It means a DB hit but at least I get type safetyRyan
08/26/2021, 1:03 PMPieter
08/26/2021, 1:07 PMJay Bell
08/26/2021, 2:25 PMPieter
09/01/2021, 10:36 PMJay Bell
09/02/2021, 5:45 PM// this is the auto generated type from prisma
type Post {
title: string;
}
class PostEntity implements Post {
title: string;
constructor() {
this.title = '';
}
}
Then you can do this to get the properties
Object.getOwnPropertyNames(new Post());
Although thats a little dirty, and you need to define a constructor that sets the props since they won’t be included in the JS code.
You could also do it without classes
const post: Post = { title: '' };
Object.getOwnPropertyNames(post);