feat(modpacks): implement simple zip importer and API

This commit is contained in:
2025-06-18 12:41:27 +03:00
parent 5e609017f0
commit ca182d6d6f
9 changed files with 274 additions and 45 deletions

View File

@@ -1,29 +1,31 @@
package database
import (
"database/sql"
"context"
"log"
"os"
_ "github.com/jackc/pgx/v5/stdlib"
"github.com/jackc/pgx/v5/pgxpool"
)
// Connect устанавливает соединение с базой данных PostgreSQL
func Connect() *sql.DB {
// Connect устанавливает соединение с базой данных PostgreSQL, используя пул соединений pgx.
func Connect() *pgxpool.Pool {
connStr := os.Getenv("DATABASE_URL")
if connStr == "" {
log.Fatal("DATABASE_URL environment variable is not set")
}
db, err := sql.Open("pgx", connStr)
// Создаем пул соединений
pool, err := pgxpool.New(context.Background(), connStr)
if err != nil {
log.Fatalf("Unable to connect to database: %v\n", err)
log.Fatalf("Unable to create connection pool: %v\n", err)
}
if err = db.Ping(); err != nil {
// Проверяем, что соединение действительно установлено
if err = pool.Ping(context.Background()); err != nil {
log.Fatalf("Unable to ping database: %v\n", err)
}
log.Println("Successfully connected to PostgreSQL!")
return db
log.Println("Successfully connected to PostgreSQL using pgxpool!")
return pool
}