GetExportArchive gets a export archive.
(ctx context.Context, workspaceID string, resourceID string)
| 22 | |
| 23 | // GetExportArchive gets a export archive. |
| 24 | func (s *Store) GetExportArchive(ctx context.Context, workspaceID string, resourceID string) (*ExportArchiveMessage, error) { |
| 25 | q := qb.Q().Space(` |
| 26 | SELECT |
| 27 | resource_id, |
| 28 | workspace, |
| 29 | created_at, |
| 30 | bytes, |
| 31 | payload |
| 32 | FROM export_archive |
| 33 | WHERE resource_id = ? |
| 34 | `, resourceID).And("workspace = ?", workspaceID) |
| 35 | |
| 36 | query, args, err := q.ToSQL() |
| 37 | if err != nil { |
| 38 | return nil, errors.Wrapf(err, "failed to build sql") |
| 39 | } |
| 40 | |
| 41 | var exportArchive ExportArchiveMessage |
| 42 | var bytesVal, payload []byte |
| 43 | if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan( |
| 44 | &exportArchive.ResourceID, |
| 45 | &exportArchive.Workspace, |
| 46 | &exportArchive.CreatedAt, |
| 47 | &bytesVal, |
| 48 | &payload, |
| 49 | ); err != nil { |
| 50 | if err.Error() == "sql: no rows in result set" { |
| 51 | return nil, nil |
| 52 | } |
| 53 | return nil, err |
| 54 | } |
| 55 | exportArchivePayload := &storepb.ExportArchivePayload{} |
| 56 | if err := common.ProtojsonUnmarshaler.Unmarshal(payload, exportArchivePayload); err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | exportArchive.Payload = exportArchivePayload |
| 60 | exportArchive.Bytes = bytesVal |
| 61 | |
| 62 | return &exportArchive, nil |
| 63 | } |
| 64 | |
| 65 | // CreateExportArchive creates a export archive. |
| 66 | func (s *Store) CreateExportArchive(ctx context.Context, create *ExportArchiveMessage) (*ExportArchiveMessage, error) { |