stephenafamo / bob

SQL query builder and ORM/Factory generator for Go with support for PostgreSQL, MySQL and SQLite
https://bob.stephenafamo.com
MIT License
701 stars 37 forks source link

Allow underscores in enum variable names #218

Closed stephenafamo closed 1 month ago

stephenafamo commented 1 month ago

Fixes #216

cloudflare-pages[bot] commented 1 month ago

Deploying bob with  Cloudflare Pages  Cloudflare Pages

Latest commit: 02138f0
Status:⚡️  Build in progress...

View logs

atzedus commented 1 month ago

Hi! I checked it. All ok with underscore, but there other problem. Are you sure that it needed at all? Golang and pgsql very familiar with unicode. So, what the problem is...

Example unicode enum:

create type unicode_enum as enum ('hello', 'привет', 'こんにちは', '안녕하세요', 'hello_with_underscore');

This will generate invalid code:

// Enum values for UnicodeEnum
const (
    UnicodeEnumHello               UnicodeEnum = "hello"
    UnicodeEnum                    UnicodeEnum = "привет"
    UnicodeEnum                    UnicodeEnum = "こんにちは"
    UnicodeEnum                    UnicodeEnum = "안녕하세요"
    UnicodeEnumHelloWithUnderscore UnicodeEnum = "hello_with_underscore"
)

But for golang the is no problem to have something like:

const (
    UnicodeEnumHello UnicodeEnum = "hello"
    UnicodeEnumПривет UnicodeEnum = "привет"
    UnicodeEnumこんにちは UnicodeEnum = "こんにちは"
    UnicodeEnum안녕하세요 UnicodeEnum = "안녕하세요"
    UnicodeEnumHelloWithUnderscore UnicodeEnum = "hello_with_underscore"
)

Yes, I understand that in the real world hardly anyone would do this. But pgsql and golang allows it.

stephenafamo commented 1 month ago

Thanks for spotting this bug @atzedus

This should work already, but there was an issue with Title-Casing the unicode characters. This should be fixed by #219