FloorVisualizer/internal/repository/gorm.go

25 lines
467 B
Go
Raw Permalink Normal View History

package repository
import (
"database/sql"
"fmt"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
// GDB is the global GORM instance, initialized after DB connect.
var GDB *gorm.DB
// InitGORM wraps an existing *sql.DB with GORM.
func InitGORM(db *sql.DB) error {
gdb, err := gorm.Open(postgres.New(postgres.Config{Conn: db}), &gorm.Config{
SkipDefaultTransaction: true,
})
if err != nil {
return fmt.Errorf("gorm init: %w", err)
}
GDB = gdb
return nil
}