MCPcopy Create free account
hub / github.com/bytebase/bytebase / GetWorkspaceByID

Method GetWorkspaceByID

backend/store/workspace.go:57–75  ·  view source on GitHub ↗

GetWorkspaceByID gets a workspace by its resource ID. Returns (nil, nil) if not found.

(ctx context.Context, resourceID string)

Source from the content-addressed store, hash-verified

55// GetWorkspaceByID gets a workspace by its resource ID.
56// Returns (nil, nil) if not found.
57func (s *Store) GetWorkspaceByID(ctx context.Context, resourceID string) (*WorkspaceMessage, error) {
58 var workspace WorkspaceMessage
59 var payloadBytes []byte
60 if err := s.GetDB().QueryRowContext(ctx,
61 `SELECT resource_id, payload FROM workspace WHERE resource_id = $1 AND deleted = FALSE`,
62 resourceID,
63 ).Scan(&workspace.ResourceID, &payloadBytes); err != nil {
64 if err == sql.ErrNoRows {
65 return nil, nil
66 }
67 return nil, errors.Wrap(err, "failed to get workspace")
68 }
69 payload := &storepb.WorkspacePayload{}
70 if err := common.ProtojsonUnmarshaler.Unmarshal(payloadBytes, payload); err != nil {
71 return nil, errors.Wrap(err, "failed to unmarshal workspace payload")
72 }
73 workspace.Payload = payload
74 return &workspace, nil
75}
76
77// GetWorkspaceID returns the workspace resource ID.
78// Returns ("", nil) if no workspace exists.

Callers 4

getUsedFeaturesMethod · 0.80
GetWorkspaceMethod · 0.80
UpdateWorkspaceMethod · 0.80
sendInviteEmailsMethod · 0.80

Calls 3

GetDBMethod · 0.95
ScanMethod · 0.80
UnmarshalMethod · 0.80

Tested by

no test coverage detected