CI / Core-Modul (Build/Vet/Test) (push) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (push) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (push) Canceled after 0s
CI / Web (dms-browser) (push) Canceled after 0s
CI / Web (pdf-viewer) (push) Canceled after 0s
CI / Web (shl) (push) Canceled after 0s
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
31 lines
980 B
Go
31 lines
980 B
Go
package batchsplit
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
// Store merkt sich die Pruefsummen bereits aufgeteilter Stapel.
|
|
type Store struct{ pool *pgxpool.Pool }
|
|
|
|
func NewStore(pool *pgxpool.Pool) *Store { return &Store{pool: pool} }
|
|
|
|
func (s *Store) Seen(ctx context.Context, checksum string) (bool, error) {
|
|
var seen bool
|
|
if err := s.pool.QueryRow(ctx, `SELECT EXISTS (SELECT 1 FROM batch_deliveries WHERE checksum_sha256 = $1)`, checksum).Scan(&seen); err != nil {
|
|
return false, fmt.Errorf("batchsplit: lieferung pruefen: %w", err)
|
|
}
|
|
return seen, nil
|
|
}
|
|
|
|
func (s *Store) Record(ctx context.Context, checksum, sourceName string, parts int) error {
|
|
if _, err := s.pool.Exec(ctx, `
|
|
INSERT INTO batch_deliveries (checksum_sha256, source_name, part_count) VALUES ($1, $2, $3)
|
|
ON CONFLICT (checksum_sha256) DO NOTHING`, checksum, sourceName, parts); err != nil {
|
|
return fmt.Errorf("batchsplit: lieferung vermerken: %w", err)
|
|
}
|
|
return nil
|
|
}
|