Skip to content

Commit

Permalink
added config for custom driver
Browse files Browse the repository at this point in the history
  • Loading branch information
ytsruh committed Mar 11, 2024
1 parent 7544227 commit 930b5eb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,30 @@ type Dialector struct {
Conn gorm.ConnPool
}

type Config struct {
DriverName string
DSN string
Conn gorm.ConnPool
}

func Open(dsn string) gorm.Dialector {
return &Dialector{DSN: dsn}
}

func New(config Config) gorm.Dialector {
return &Dialector{DSN: config.DSN, DriverName: config.DriverName, Conn: config.Conn}
}

func (dialector Dialector) Name() string {
return "sqlite"
}

func (dialector Dialector) Initialize(db *gorm.DB) (err error) {
if dialector.DriverName == "" {
dialector.DriverName = DriverName
}

if dialector.Conn != nil {
db.ConnPool = dialector.Conn
} else if dialector.DriverName != "" {
db.ConnPool, err = sql.Open(dialector.DriverName, dialector.DSN)
} else {
conn, err := sql.Open(dialector.DriverName, dialector.DSN)
if err != nil {
Expand Down

0 comments on commit 930b5eb

Please sign in to comment.