Skip to content
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

Casing for Prisma Client model and field names #5035

Closed
janpio opened this issue Mar 16, 2020 · 8 comments
Closed

Casing for Prisma Client model and field names #5035

janpio opened this issue Mar 16, 2020 · 8 comments
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: dx

Comments

@janpio
Copy link
Member

janpio commented Mar 16, 2020

Similar to #1851, but Client level

Upper case models produce Prisma client call with a weird casing:

model ATOMS {
  ATOM_TYPE                   Int?
  CHARGE                      Float?
  ELEMENT                     String?
  ID                          Int         @default(0) @id
  DRUG_ID                     DRUGS?
  bONDS_ATOMSToBONDS_ATOM1_ID BONDS[]     @relation("ATOMSToBONDS_ATOM1_ID")
  bONDS_ATOMSToBONDS_ATOM2_ID BONDS[]     @relation("ATOMSToBONDS_ATOM2_ID")
  rING_ATOM                   RING_ATOM[]

  @@index([DRUG_ID], name: "ATOMS_DRUG_ID")
}

Casing in generated client:

image

Same applies for field names like bONDS_ATOMSToBONDS_ATOM1_ID.

Right now this exists: https://github.com/prisma/prisma-client-js/blob/ffa2f18bd5dc9390380f01d3f68a9c81adeb1086/packages/photon/src/runtime/getPrismaClient.ts#L349

This should be removed, and everything that is similar: The schema is the source of truth for capitalization of model and field names.

@schickling
Copy link
Member

Re-opening as we've undone this decision. We'll have to revisit this.

@schickling schickling reopened this Mar 17, 2020
@pantharshit00 pantharshit00 transferred this issue from prisma/prisma-client-js Jan 13, 2021
@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: dx labels Jan 13, 2021
@timsuchanek
Copy link
Contributor

Until we have more reportings about this, we will close this.

@m4nuC
Copy link

m4nuC commented Jul 13, 2021

This actually breaks camel case naming convention when acronyms should be capitalized, eg. we have an NFT model, it becomes nFT.

@pantharshit00
Copy link
Contributor

We lowercase the first letter now. I don't think we can change that now, that will break things for existing users.

@pantharshit00
Copy link
Contributor

pantharshit00 commented Jul 13, 2021

You can try using a map:

model nft {
 // fields ..
 // ..
 @@map("NFT")
}

This will provide prisma.nft in the client and database table will be called NFT

@m4nuC
Copy link

m4nuC commented Jul 14, 2021

@pantharshit00 thanks, I will try this.

@kukaki
Copy link

kukaki commented Aug 7, 2021

This actually breaks camel case naming convention when acronyms should be capitalized, eg. we have an NFT model, it becomes nFT.

Yeah. In our case, one of the models name is MEPAction (as per the naming conventions it should be MEPAction, not MepAction).

but the prisma code generated is prisma.mEPAction, it actually should be prisma.mepAction.

Just because Prisma is generating this wierd code, we need to flout the naming conventions and use MepAction instead of MEPAction.

You can try using a map:

model nft {
 // fields ..
 // ..
 @@map("NFT")
}

This will provide prisma.nft in the client and database table will be called NFT

@pantharshit00 This names the database table name as nft. But the prisma code generated is still prisma.nFT

@pantharshit00
Copy link
Contributor

pantharshit00 commented Aug 8, 2021

As I already told here we can't change it. Here is the lowercase function we use:

export function lowerCase(name: string): string {
return name.substring(0, 1).toLowerCase() + name.substring(1)
}

It is very simple and just lowercase the first letter. It is designed so that generally convention of using Capitalized Case in Prisma schema reflects fine in the client. When you use existing database models we recommend using @map if your model doesn't follow the capitalize case.

Changing the lowercase function also means a breaking change for all users.

@prisma prisma locked as resolved and limited conversation to collaborators Aug 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: dx
Projects
None yet
Development

No branches or pull requests

7 participants