- Go API server with PostgreSQL + Redis - AI floor replacement (OpenRouter Gemini) - Product database (10 brands, 3539 products) - Recommendation engine, calculator, articles - Redis async queue + worker pool - Hot product caching, brand view tracking - JWT auth, favorites, projects - Docker deployment ready Co-Authored-By: Claude <noreply@anthropic.com>
25 lines
467 B
Go
25 lines
467 B
Go
package repository
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
|
|
"gorm.io/driver/postgres"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// GDB is the global GORM instance, initialized after DB connect.
|
|
var GDB *gorm.DB
|
|
|
|
// InitGORM wraps an existing *sql.DB with GORM.
|
|
func InitGORM(db *sql.DB) error {
|
|
gdb, err := gorm.Open(postgres.New(postgres.Config{Conn: db}), &gorm.Config{
|
|
SkipDefaultTransaction: true,
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("gorm init: %w", err)
|
|
}
|
|
GDB = gdb
|
|
return nil
|
|
}
|