Support Prisma's multiSchema
feature via workaround
#56
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Prisma supports multi-schemas via the
multiSchema
preview feature (https://www.prisma.io/docs/guides/other/multi-schema), but the schemas are not appended to the table names generated byprisma-kysely
.Sadly,
@prisma/generator-helper
doesn't expose the model schemas set via@@schema("schemaName")
, so a workaround is needed for now. I've opened an issue for Prisma to fix this here: prisma/prisma#19987Changes
multiSchema
and@@schema()
attributes.@@mrleebo/prisma-ast
to parse the datamodel separately and matches the schemas with the correct model. This is a workaround and is only needed until Prisma exposes the schema attribute on theDMMF.Model
objects themselves.DB
type (like whatkysely-codegen
does)multiSchema
is not enabled.Alternative solutions
@@mrleebo/prisma-ast
then we could do it via bracket matching instead, though it's a bit more complex and potentially error prone.Example output
Toggle example
prisma.schema
(partial)Generated DB type before PR:
Generated DB type after PR: