github.com/abolfazlbeh/zhycan@v0.0.0-20230819144214-24cf38237387/pkg/db/model.go (about)

     1  package db
     2  
     3  import (
     4  	"github.com/abolfazlbeh/zhycan/internal/db"
     5  	"go.mongodb.org/mongo-driver/mongo"
     6  	"gorm.io/gorm"
     7  )
     8  
     9  // GetDb - Get *gorm.DB instance from the underlying interfaces
    10  func GetDb(instanceName string) (*gorm.DB, error) {
    11  	return db.GetManager().GetDb(instanceName)
    12  }
    13  
    14  // Migrate - migrate models on specific database
    15  func Migrate(instanceName string, models ...interface{}) error {
    16  	return db.GetManager().Migrate(instanceName, models)
    17  }
    18  
    19  // AttachMigrationFunc -  attach migration function to be called by end user
    20  func AttachMigrationFunc(instanceName string, f func(migrator gorm.Migrator) error) error {
    21  	return db.GetManager().AttachMigrationFunc(instanceName, f)
    22  }
    23  
    24  // GetMongoDb - Get *mongo.Client instance from the underlying interfaces
    25  func GetMongoDb(instanceName string) (*mongo.Client, error) {
    26  	return db.GetManager().GetMongoDb(instanceName)
    27  }