Skip to content

Commit

Permalink
active_provider
Browse files Browse the repository at this point in the history
  • Loading branch information
AdeelK93 committed Aug 9, 2024
1 parent 8cb03ee commit 2385d02
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/prisma/generator/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class Schema(BaseModel):

@classmethod
def from_data(cls, data: AnyData) -> 'Schema':
models = [Model(info=model) for model in data.dmmf.datamodel.models]
active_provider = data.datasources[0].active_provider
models = [Model(info=model, active_provider=active_provider) for model in data.dmmf.datamodel.models]
return cls(models=models)

def get_model(self, name: str) -> 'Model':
Expand All @@ -93,6 +94,7 @@ def get_model(self, name: str) -> 'Model':

class Model(BaseModel):
info: ModelInfo
active_provider: str

if PYDANTIC_V2:
model_config: ClassVar[ConfigDict] = ConfigDict(ignored_types=(cached_property,))
Expand Down Expand Up @@ -159,25 +161,26 @@ def order_by(self) -> PrismaType:
for field in self.info.scalar_fields
]
# Full-text search relevance sorting
relevance_type = PrismaDict(
name=f'_{model}_RelevanceOrderByInput',
total=True,
fields={
'_relevance': f'_{model}_RelevanceInner',
},
subtypes=[
PrismaDict(
name=f'_{model}_RelevanceInner',
total=True,
fields={
'fields': f'List[{model}ScalarFieldKeys]',
'search': 'str',
'sort': 'SortOrder',
},
)
],
)
variants.append(relevance_type)
if self.active_provider in {'postgresql', 'mysql'}:
relevance_type = PrismaDict(
name=f'_{model}_RelevanceOrderByInput',
total=True,
fields={
'_relevance': f'_{model}_RelevanceInner',
},
subtypes=[
PrismaDict(
name=f'_{model}_RelevanceInner',
total=True,
fields={
'fields': f'List[{model}ScalarFieldKeys]',
'search': 'str',
'sort': 'SortOrder',
},
)
],
)
variants.append(relevance_type)
return PrismaType.from_variants(variants, name=f'{model}OrderByInput')


Expand Down

0 comments on commit 2385d02

Please sign in to comment.