func Factory(cfg *utils.ServerConfig) (*ORM, error) {
	db, err := gorm.Open(cfg.Database.Dialect, cfg.Database.DSN)
	if err != nil {
		logger.Panic("[ORM] err: ", err)
	}
	orm := &ORM{DB: db}
	db.LogMode(cfg.Database.LogMode)
	if cfg.Database.AutoMigrate {
		err = migration.ServiceAutoMigration(orm.DB)
		if err != nil {
			logger.Error("[ORM.autoMigrate] err: ", err)
		}
	}
	logger.Info("[ORM] Database connection initialized.")
	return orm, nil
}
Factory creates a db connection with the selected dialect and connection
string
package orm
import (
	"errors"
	"fmt"
	"github.com/cmelgarejo/go-gql-server/pkg/utils/consts"
	"github.com/cmelgarejo/go-gql-server/internal/gql/resolvers/transformations"
	"github.com/markbates/goth"
	"github.com/cmelgarejo/go-gql-server/internal/logger"
	"github.com/cmelgarejo/go-gql-server/internal/orm/models"
	"github.com/cmelgarejo/go-gql-server/internal/orm/migration"
	"github.com/cmelgarejo/go-gql-server/pkg/utils"
	_ "github.com/jinzhu/gorm/dialects/postgres"
	"github.com/jinzhu/gorm"
)
var (
	sUserTbl  = "User"
	nestedFmt = "%s.%s"
)
type ORM struct {
	DB *gorm.DB
}