-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Library to parse schema.prisma
#515
Comments
Actually, I am guessing generators are a way to do that... |
We are aiming for a Prisma SDK release that will provide a general library for this purpose. (https://github.com/prisma/specs/tree/master/sdk-js/generators) Right now all of our datamodel parsing logic is written in Rust(https://github.com/prisma/prisma-engine/tree/master/libs/datamodel) so you will need an RPC call to the binary to retrieve a parsed datamodel but SDK will simplify this flow. Actually right now photon also gives you the parsed dmmf(datamodel meta format) as an exported variable which you can consume for now. |
Looping in @Weakky as he's working on the Prisma SDK. |
Fix Error's meta property typing Former-commit-id: 8dcb00e
Just discussed this with @Weakky recently. Our use case: we need to programmatically make some tweaks to the introspected schema, tweaks which Prisma doesn't (and arguably shouldn't) natively support:
We could either:
Database schema is currently managed by Sequelize, and the first step of transitioning to Prisma would be to keep Sequelize manage the schema while we progressively port queries to Prisma, until Prisma manages the rest. |
This is something that is not documented but you can use the import { getDMMF } from '@prisma/sdk'
const dmmf = getDMMF({ datamodel: "model User { id String @id }" }) Note that this is subject to change without any notification. Also, note that SDK doesn't come with a DMMF printer. |
I am playing around with the My idea is to transform the model and field name in the However, I can't seem to find anything in the output Here's the input schema and the dump of the DMMF, https://gist.github.com/ExiaSR/7e7c8a56bee768410f5ea024da39d9e9 For now I guess I could add an additional property in DMMF.Field to represent the |
@ExiaSR i'll be interested in seeing your deserialiser to prisma schema file. Is it published somewhere ? |
@olup It's undergoing internal approval for Open Source, so stay tuned (expecting sometime next week). |
@olup https://github.com/IBM/prisma-schema-transformer |
Is there anything like the deserializer planned for the |
An exposed and documented Prisma serializer/deserializer would be great for the community to build tools around Prisma. It would be great to pass the schema through a custom transformer function to output a GraphQL schema, to name a very common use case. |
I agree, this would fuel innovation and truely distinguish Prisma from other ORMs. |
This library does a fairly decent job of parsing, modifying and reprinting the prisma schema: https://github.com/MrLeebo/prisma-ast |
We just released another complete Prisma schema parser/formatter written in Typescript as well: https://github.com/loancrate/prisma-schema-parser It doesn't have the fluent schema builder of the one above, but is more directly based on the PEG grammar of the Prisma engine. It also has helpers for accessing attribute values, tracking of source locations, and 100% test coverage. We used it for migrating to a GraphQL SDL-centric workflow, where Prisma schema, API schema, validation, documentation, etc. are based on a core SDL annotated with directives. |
Having read #318 and toying myself with the idea of a simple admin panel to create models with fields and relations, generate a nexus-prisma revolvers file and trigger database migrations (akin to Strapi or 8base, but much simpler) I was wondering if you open-sourced a library to parse the
schema.prisma
into something usable by code (I mean, ultimately, a javascript object) ? That would permit third party developer to create tools to plug into theprisma 2
environment.Also, I was wondering why this format have been chosen over simple JSON or YAML/TOML structure ?
My love goes to this project.
The text was updated successfully, but these errors were encountered: