go-gorm / postgres

GORM PostgreSQL driver
MIT License
234 stars 123 forks source link

use DriverName but unkonw driver #183

Closed zzy2210 closed 1 year ago

zzy2210 commented 1 year ago

Your Question

I tried to use other drivers by way of the “drivername” parameter.

but it return error "sql: unknown driver"

What should I do?

The document you expected this should be explained

the code like :

import (
    "fmt"

    "gorm.io/driver/postgres"
    "gorm.io/gorm"

    _ "gitee.com/opengauss/openGauss-connector-go-pq"
)

func NewClient() (*gorm.DB, error) {
    return gorm.Open(postgres.New(postgres.Config{
        DSN:                  fmt.Sprintf(dsnLayout, ip, user, password,dbname,port),
        PreferSimpleProtocol: true, // disables implicit prepared statement usage
        DriverName:           "openGauss-connector-go-pq",
    }), &gorm.Config{})
}

Expected answer

saeidee commented 1 year ago

You might try it like this:

return gorm.Open(postgres.New(postgres.Config{
        DSN:                  fmt.Sprintf(dsnLayout, ip, user, password,dbname,port),
        PreferSimpleProtocol: true, // disables implicit prepared statement usage
        DriverName:           "opengauss",
    }), &gorm.Config{})
zzy2210 commented 1 year ago

You might try it like this:

return gorm.Open(postgres.New(postgres.Config{
      DSN:                  fmt.Sprintf(dsnLayout, ip, user, password,dbname,port),
      PreferSimpleProtocol: true, // disables implicit prepared statement usage
      DriverName:           "opengauss",
  }), &gorm.Config{})

thanks~ i will try it

saeidee commented 1 year ago

Closing the issue since it is not related to this repository.