From 17e1049acc97a16c49a95e811351b65ecc97a995 Mon Sep 17 00:00:00 2001 From: Cyprien <42470486+Cypaaa@users.noreply.github.com> Date: Sat, 2 Dec 2023 20:31:10 +0100 Subject: [PATCH] Update database Database now gets a gorm.Dialector instead of an interface --- database.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/database.go b/database.go index bcb81f9..2a0728b 100644 --- a/database.go +++ b/database.go @@ -4,25 +4,16 @@ import ( "gorm.io/gorm" ) -// Driver interface, required to create a new database connection -// could be mysql, postgres, sqlite, etc... Or even custom ones -type Driver interface { - New() gorm.Dialector - Open(dns string) gorm.Dialector -} - // Database struct type Database struct { - conn *gorm.DB - dns string - driver Driver + conn *gorm.DB + dialector gorm.Dialector } // NewDatabase creates a new database connection -func NewDatabase(driver Driver, dns string) (*Database, error) { +func NewDatabase(dialector gorm.Dialector) (*Database, error) { db := &Database{ - dns: dns, - driver: driver, + dialector: dialector, } err := db.Init() return db, err @@ -35,7 +26,7 @@ func (d *Database) Conn() *gorm.DB { // Init initializes the database connection func (d *Database) Init() error { - conn, err := gorm.Open(d.driver.Open(d.dns), &gorm.Config{}) + conn, err := gorm.Open(d.dialector, &gorm.Config{}) if err != nil { return err }