Hi there!!! I’m trying to build some CMS lib for a...
# orm-help
b
Hi there!!! I’m trying to build some CMS lib for a framework and I would like to generate the backend code based on the schema. So that anyone can plug it into their existing apps. Is there a way to introspect and/or get an AST from Prisma so that I can generate some types and extend the config of my lib?
n
Hey Bernat 👋 If you want the metadata from the schema file i.e.
schema.prisma
, then you can use
dmmf
property: You can get all the metadata for your entire schema in the following manner:
Copy code
const prisma = new PrismaClient()

// @ts-ignore
console.log(prisma._dmmf)
This will give you all the details for the models and relations along with the data types. Please note that this is not an official API but an API that is used internally so this could be changed in future.
j
A better/alternative way would probably to create a custom generator for Prisma CLI, that also gets the DMMF as input and you can then create files and structures as you need them.