From bd9cf230e4435ae4728105b1b869a4a0ed82dba2 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Fri, 27 Jun 2025 14:52:34 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20type=20I?= =?UTF-8?q?ConnectionTransaction=20interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- postgres_pgx/postgres_pgx.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/postgres_pgx/postgres_pgx.go b/postgres_pgx/postgres_pgx.go index 935e01f3..05bf3865 100644 --- a/postgres_pgx/postgres_pgx.go +++ b/postgres_pgx/postgres_pgx.go @@ -10,6 +10,7 @@ import ( "github.com/ManyakRus/starter/log" "github.com/ManyakRus/starter/port_checker" "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgconn" "strings" "time" @@ -539,3 +540,22 @@ func Ping_err(ctxMain context.Context) error { _, err = Conn.Exec(ctx, ";") return err } + +// IConnectionTransaction - интерфейс для работы с базой данных +// объединяет в себе функции pgx.Conn, pgxpool.Pool и pgx.Tx +// чтобы передавать в функцию любой их них +type IConnectionTransaction interface { + // Transaction management + Begin(ctx context.Context) (pgx.Tx, error) + + // Query execution + Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error) + Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error) + QueryRow(ctx context.Context, sql string, args ...any) pgx.Row + + // Batch operations + SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults + + // Bulk copy operations + CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error) +}