feat: 初始化平台总后台与核心API
This commit is contained in:
17
backend/internal/database/database.go
Normal file
17
backend/internal/database/database.go
Normal file
@@ -0,0 +1,17 @@
|
||||
// Package database 负责 PostgreSQL 连接、迁移和演示数据初始化。
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
// Connect 建立 PostgreSQL 连接池;数据库地址必须通过环境变量提供。
|
||||
func Connect(ctx context.Context, databaseURL string) (*pgxpool.Pool, error) {
|
||||
if databaseURL == "" {
|
||||
return nil, errors.New("缺少 DATABASE_URL 环境变量")
|
||||
}
|
||||
return pgxpool.New(ctx, databaseURL)
|
||||
}
|
||||
Reference in New Issue
Block a user