Can anyone tell me what the API to extract a schem...
# orm-help
j
Can anyone tell me what the API to extract a schema out of a database? I need the metadata such as the tables and column names with all data types. Thanks
r
@Johan 👋 If you want this metadata from
schema.prisma
, then you can use
dmmf
: Yes, 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.
j
Thanks for responding. However what i need is to get the metadata from the existing database. The dmmf gives me the meta data defined in schema.prisma only. Please correct me if I was wrong. Thanks again
j
That would be
npx prisma db pull
(formerly known as
npx prisma introspect
). This will give you a new Prisma schema.
If you want the
CREATE
statements in pure DDL SQL, optimally use a third party tool.
plus one +1 1