feat(modpacks): implement simple zip importer and API
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user