gorm/dialects/postgres/postgres.go

34 lines
576 B
Go
Raw Normal View History

2020-02-03 05:40:03 +03:00
package postgres
import (
"database/sql"
"github.com/jinzhu/gorm"
"github.com/jinzhu/gorm/callbacks"
_ "github.com/lib/pq"
)
type Dialector struct {
DSN string
}
func Open(dsn string) gorm.Dialector {
return &Dialector{DSN: dsn}
}
func (dialector Dialector) Initialize(db *gorm.DB) (err error) {
// register callbacks
callbacks.RegisterDefaultCallbacks(db)
db.DB, err = sql.Open("postgres", dialector.DSN)
return
}
func (Dialector) Migrator() gorm.Migrator {
return nil
}
func (Dialector) BindVar(stmt *gorm.Statement, v interface{}) string {
return "?"
}