Skip to content

Commit 290eee3

Browse files
Add CopyFrom to transaction
1 parent d4913a9 commit 290eee3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pkg/storage/postgres/transaction.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package postgres
22

33
import (
44
"context"
5+
"io"
56

67
"github.com/go-pg/pg/v10"
78
"github.com/pkg/errors"
@@ -105,3 +106,13 @@ func (t *Transaction) Exec(ctx context.Context, query any, params ...any) (int,
105106
}
106107
return result.RowsAffected(), nil
107108
}
109+
110+
// CopyFrom -
111+
func (t *Transaction) CopyFrom(r io.Reader, query string, args ...any) error {
112+
if t.tx == nil {
113+
return errNilTx
114+
}
115+
116+
_, err := t.tx.CopyFrom(r, query, args...)
117+
return err
118+
}

pkg/storage/storage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package storage
22

33
import (
44
"context"
5+
"io"
56
)
67

78
// SortOrder - asc or desc
@@ -72,6 +73,7 @@ type Transaction interface {
7273
Close(ctx context.Context) error
7374
HandleError(ctx context.Context, err error) error
7475
Exec(ctx context.Context, query any, params ...any) (int, error)
76+
CopyFrom(r io.Reader, query string, args ...any) error
7577
}
7678

7779
// Model - general data type interface

0 commit comments

Comments
 (0)