Initial commit

This commit is contained in:
Dezone
2025-09-02 10:14:12 +00:00
commit 5ea90d5c0e
27 changed files with 89 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
package postgres
import (
"fmt"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
type DBConnOptions struct {
User string
Pass string
Host string
Port uint
DBName string
Schema string
}
func (o DBConnOptions) PostgresDSN() string {
schema := o.Schema
if schema == "" {
schema = "public"
}
return fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s search_path=%s",
o.Host, o.Port, o.User, o.Pass, o.DBName, schema)
}
func NewPsqlGormConnection(opt DBConnOptions) (*gorm.DB, error) {
return gorm.Open(postgres.Open(opt.PostgresDSN()), &gorm.Config{
Logger: logger.Discard,
})
}