pg icon indicating copy to clipboard operation
pg copied to clipboard

Enhancement: provide API to get column name from struct field name

Open sproutworks opened this issue 4 years ago • 0 comments

Detailed Description

I would like to be able to a column name for a field in a struct. For example if I have a struct with a 'FirstName' field, it would return 'first_name'. Ideally this would also support custom column mappings.

I found some code in orm/table.go which uses an internal underscore method to create the column name. For now I can copy some of the internal logic, but this is not ideal.

Possible Implementation

A new method in pg package can return field name to column name mappings.

db.GetColumnName('FirstName') // returns "first_name"

sproutworks avatar Dec 16 '20 21:12 sproutworks