fix(postgres):lab4 add missing ExistingKeys to AttachmentRepo

This commit is contained in:
Голиков Maximillian Антон
2026-10-22 16:10:23 +03:00
parent 4d28ae549a
commit 4a94b0a5a0
@@ -174,3 +174,27 @@ func (r *AttachmentRepo) DeletePending(ctx context.Context, id string) error {
}
return nil
}
func (r *AttachmentRepo) ExistingKeys(ctx context.Context, keys []string) ([]string, error) {
if len(keys) == 0 {
return []string{}, nil
}
const q = `SELECT object_key FROM attachments WHERE object_key = ANY($1::text[])`
rows, err := r.pool.Query(ctx, q, keys)
if err != nil {
return nil, mapError(err)
}
defer rows.Close()
out := make([]string, 0, len(keys))
for rows.Next() {
var k string
if err := rows.Scan(&k); err != nil {
return nil, mapError(err)
}
out = append(out, k)
}
return out, mapError(rows.Err())
}
var _ domain.AttachmentRepository = (*AttachmentRepo)(nil)