go-gorm / postgres

GORM PostgreSQL driver
MIT License
228 stars 120 forks source link

How to use NamingStrategy.IdentifierMaxLength in postgres driver #191

Open alidevhere opened 1 year ago

alidevhere commented 1 year ago

Describe the feature

NamingStrategy.IdentifierMaxLength has been added in gorm, which allows to override max length of 64. How to make use of this in postgres driver to change it to 63. @jinzhu i can only think of it like this :

import (
    "gorm.io/driver/postgres"
    "gorm.io/gorm"
    s "gorm.io/gorm/schema"
)

func main() {

    db, err := gorm.Open(postgres.New(postgres.Config{
        DSN:                  "host=localhost user=gorm password=gorm dbname=gorm port=9920 sslmode=disable TimeZone=Asia/Shanghai", // data source name, refer https://github.com/jackc/pgx
        PreferSimpleProtocol: true,                                                                                                  // disables implicit prepared statement usage. By default pgx automatically uses the extended protocol
    }), &gorm.Config{NamingStrategy: s.NamingStrategy{IdentifierMaxLength: 63}})

}

Related Issues

And please assign this issue to me, i will work on it commited change in gorm

a631807682 commented 1 year ago

like other drivers https://github.com/go-gorm/mysql/blob/master/mysql.go#L100

alidevhere commented 1 year ago

@jinzhu @a631807682 pull request is created for this issue

alidevhere commented 8 months ago

@jinzhu @a631807682

PR created for this issue