Paperclip/pkg/internal/database/source.go

28 lines
697 B
Go
Raw Normal View History

2024-05-17 07:59:51 +00:00
package database
import (
2024-10-27 05:13:40 +00:00
"git.solsynth.dev/hypernet/nexus/pkg/nex/cruda"
2024-11-02 02:41:31 +00:00
"git.solsynth.dev/hypernet/paperclip/pkg/internal/gap"
2024-05-17 07:59:51 +00:00
"github.com/rs/zerolog/log"
"github.com/samber/lo"
"github.com/spf13/viper"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
var C *gorm.DB
func NewSource() error {
var err error
2024-10-27 05:13:40 +00:00
dsn, err := cruda.NewCrudaConn(gap.Nx).AllocDatabase("paperclip")
C, err = gorm.Open(postgres.Open(dsn), &gorm.Config{Logger: logger.New(&log.Logger, logger.Config{
2024-05-17 07:59:51 +00:00
Colorful: true,
IgnoreRecordNotFoundError: true,
LogLevel: lo.Ternary(viper.GetBool("debug.database"), logger.Info, logger.Silent),
})})
return err
}