You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
534 B

package lib
import(
"log"
"fmt"
"os"
"github.com/joho/godotenv"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
func Connector() (*gorm.DB, error) {
// Database connection string
err:= godotenv.Load();
if(err!=nil) {
log.Fatal("Error loading .env file")
}
dsn := fmt.Sprint(os.Getenv("DATABASE_DSN"))
// Open the database connection
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
log.Fatal("failed to connect database:", err)
}
return db, err
}