This commit is contained in:
@@ -3,11 +3,11 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
"smart-search-back/internal/model"
|
||||
errs "smart-search-back/pkg/errors"
|
||||
|
||||
"git.techease.ru/Smart-search/smart-search-back/internal/model"
|
||||
errs "git.techease.ru/Smart-search/smart-search-back/pkg/errors"
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
@@ -24,6 +24,14 @@ func NewSupplierRepository(pool *pgxpool.Pool) SupplierRepository {
|
||||
}
|
||||
|
||||
func (r *supplierRepository) BulkInsert(ctx context.Context, requestID uuid.UUID, suppliers []*model.Supplier) error {
|
||||
return r.bulkInsertWithExecutor(ctx, r.pool, requestID, suppliers)
|
||||
}
|
||||
|
||||
func (r *supplierRepository) BulkInsertTx(ctx context.Context, tx pgx.Tx, requestID uuid.UUID, suppliers []*model.Supplier) error {
|
||||
return r.bulkInsertWithExecutor(ctx, tx, requestID, suppliers)
|
||||
}
|
||||
|
||||
func (r *supplierRepository) bulkInsertWithExecutor(ctx context.Context, exec DBTX, requestID uuid.UUID, suppliers []*model.Supplier) error {
|
||||
if len(suppliers) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -41,7 +49,7 @@ func (r *supplierRepository) BulkInsert(ctx context.Context, requestID uuid.UUID
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to build query", err)
|
||||
}
|
||||
|
||||
_, err = r.pool.Exec(ctx, sqlQuery, args...)
|
||||
_, err = exec.Exec(ctx, sqlQuery, args...)
|
||||
if err != nil {
|
||||
return errs.NewInternalError(errs.DatabaseError, "failed to bulk insert suppliers", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user