yesodweb / persistent

Persistence interface for Haskell allowing multiple storage methods.
MIT License
467 stars 297 forks source link

Incorrect casing for “ID” #1549

Open toastal opened 2 months ago

toastal commented 2 months ago

All implicit generated IDs such as the ID for Foo is generated as FooId. While much of the documentation uses “ID”, the code representation is incorrect casing where “ID” is the standard abbreviation form for identifiers (IDs), not “Id”. Changing this would align other correctly-cased variables in the project like DB (along with uses of IO, UUID, & FromJSON from other libs), but still leaves incorrect cases like Sql instead of SQL for the initialism ‘structured query language’ (where documentation is largely using “SQL”).

What I would expect is the implicit ID for Foo becomes FooID… all fooId columns become fooID.

Moving from ‘ID’ to ‘Id’ is losing valuable casing information & if it weren’t important, we wouldn’t be bothering with upper case letters at all in English (& other languages with bicameral scripts).

toastal commented 2 months ago

I attempted to use something like

def :: ImplicitIdDef
def =
    autoIncrementingInteger
        { iidFieldType =
            \entName ->
                FTTypeCon Nothing $ unEntityNameHS entName `mappend` "ID"
        }

to no avail to fix the situation.

toastal commented 2 months ago

What I have not tried: sed -i "s/Id/ID/g" **/*.hs & seen if everything works.

parsonsmatt commented 2 months ago

Yeah, that assumption is baked into a lot of the TH code. I don't anticipate changing that to be easy or particularly flexible.

toastal commented 2 months ago

Is there a combinator route to go, or is Template Haskell the only/preferred way?

parsonsmatt commented 2 months ago

While you can define the PersistEntity stuff yourself, it's not really easy or well-supported.