Closed BudWhiteStudying closed 2 years ago
I dug up a bit more. https://github.com/paljs/prisma-tools/blob/17d8c67f0da89c6c3303f269e4a010fc8135f072/packages/schema/src/camelCase.ts#L74
Using camelCase
from lodash
here instead of doing the work yourself would probably be enough
Welcome to Node.js v16.9.0.
Type ".help" for more information.
> const lodash = require('lodash')
undefined
> lodash.camelCase("MY_TABLE")
'myTable'
hey, @BudWhiteStudying, I think all that I need to do is add one word https://github.com/paljs/prisma-tools/blob/17d8c67f0da89c6c3303f269e4a010fc8135f072/packages/schema/src/camelCase.ts#L80
also when I am working I love to do all my work without external packages if this is small work.
Ah sure, I think that would work too. I typically try to avoid reinventing the wheel by relying on external packages when they're well established, but I completely understand your point.
Please try v4.0.2
Doesn't seem to work, although I don't understand why. I did everything from scratch with a clean schema.prisma
file.
npx prisma db pull
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
[...]
Introspecting based on datasource defined in prisma/schema.prisma …
✔ Introspected 8 models and wrote them into prisma/schema.prisma in 2.68s
This again generates a model like
model AVAILABLE_PRODUCT {
PRODUCT_ID Int @id @default(autoincrement())
}
then I ran
npx @paljs/cli@4.0.2 schema camel-case
Prisma Schema loaded from prisma/schema.prisma
✔ Your schema converted successfully
and the result is still
model AVAILABLEPRODUCT {
PRODUCTID Int @id @default(autoincrement())
}
it must give you
model AvailableProduct {
PRODUCTId Int @id @default(autoincrement())
}
and this is wrong and I released another version that has a fix v4.0.3
model AvailableProduct {
productId Int @id @default(autoincrement()) @map("PRODUCT_ID")
@@map("AVAILABLE_PRODUCT")
}
Now it works as intended, except for names without underscores i.e. the ID
column isn't converted to id
, the USER
table isn't converted to User
.
because we search for words have _
I'm trying out Prisma+pal with a database where all tables and columns are written in uppercase snake case e.g. the
AVAILABLE_PRODUCT
table has aPRODUCT_ID
column and so on.Running
pal schema camel-case
produces aschema.prisma
file where all tables and columns are still uppercased, but with no underscore e.g.I guess
pal
assumes that tables and columns are written in lowercase snake case, and just removes underscores and uppercases initials.Any suggestions on how to get out of this situation? I Thought of replacing lowercase characters with uppercase before running
pal schema camel-case
(e.g. through a Sublime RegEx) but that would mess up types e.g.Int
, which are already in the correct notation.Thanks in advance.