From 0182855e8bbdd32aa5de7ba98427abcf771084a1 Mon Sep 17 00:00:00 2001 From: JuanJoCasamitjana <73534780+JuanJoCasamitjana@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:32:04 +0200 Subject: [PATCH 1/2] Custom config struct to use custom driver like libsql just a copy of go-gorm/sqlite/pull/185 --- sqlite.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sqlite.go b/sqlite.go index b84147e..2a3c8c1 100644 --- a/sqlite.go +++ b/sqlite.go @@ -26,21 +26,29 @@ 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 { From 9f3eee035b2af72b5478c9517dbf94738f6a7bdb Mon Sep 17 00:00:00 2001 From: JuanJoCasamitjana <73534780+JuanJoCasamitjana@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:42:12 +0200 Subject: [PATCH 2/2] fix bad copy --- sqlite.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sqlite.go b/sqlite.go index 2a3c8c1..d9208e6 100644 --- a/sqlite.go +++ b/sqlite.go @@ -45,10 +45,11 @@ func (dialector Dialector) Name() string { } 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 {