All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: twhelp/core#117
45 lines
1020 B
Go
45 lines
1020 B
Go
package bundb
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.dwysokinski.me/twhelp/core/internal/bundb/internal/model"
|
|
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
|
"github.com/uptrace/bun"
|
|
"go.opentelemetry.io/otel/codes"
|
|
)
|
|
|
|
type PlayerSnapshot struct {
|
|
db *bun.DB
|
|
}
|
|
|
|
func NewPlayerSnapshot(db *bun.DB) *PlayerSnapshot {
|
|
return &PlayerSnapshot{db: db}
|
|
}
|
|
|
|
func (p *PlayerSnapshot) Create(ctx context.Context, params ...domain.CreatePlayerSnapshotParams) error {
|
|
ctx, span := tracer.Start(ctx, "PlayerSnapshot.Create")
|
|
defer span.End()
|
|
|
|
if len(params) == 0 {
|
|
return nil
|
|
}
|
|
|
|
snapshots := make([]model.PlayerSnapshot, 0, len(params))
|
|
for _, param := range params {
|
|
snapshots = append(snapshots, model.NewPlayerSnapshot(param))
|
|
}
|
|
|
|
if _, err := p.db.NewInsert().
|
|
Model(&snapshots).
|
|
Returning("NULL").
|
|
Exec(ctx); err != nil {
|
|
span.RecordError(err)
|
|
span.SetStatus(codes.Error, err.Error())
|
|
return fmt.Errorf("something went wrong while inserting player snapshots into the db: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|