This commit is contained in:
2025-11-12 09:41:52 +03:00
commit 2a8566712a
44 changed files with 2602 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
package database
import (
"context"
"fmt"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool"
"log/slog"
"os"
)
type Client interface {
Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)
Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
Begin(ctx context.Context) (pgx.Tx, error)
Ping(ctx context.Context) error
}
func NewClient(ctx context.Context, connUrl string, logger *slog.Logger) (*pgxpool.Pool, error) {
pool, err := pgxpool.New(ctx, connUrl)
if err != nil {
fmt.Println(fmt.Fprintf(os.Stderr, "Unable to create connection pool: %v\n", err))
logger.Error("Unable to create connection pool: ", err)
os.Exit(1)
}
return pool, nil
}