MCPcopy Index your code
hub / github.com/bytebase/bytebase / getWorkspace

Method getWorkspace

backend/store/workspace.go:36–53  ·  view source on GitHub ↗

getWorkspace returns the workspace. Returns (nil, nil) if no workspace exists.

(ctx context.Context)

Source from the content-addressed store, hash-verified

34
35// getWorkspace returns the workspace. Returns (nil, nil) if no workspace exists.
36func (s *Store) getWorkspace(ctx context.Context) (*WorkspaceMessage, error) {
37 var workspace WorkspaceMessage
38 var payloadBytes []byte
39 if err := s.GetDB().QueryRowContext(ctx,
40 `SELECT resource_id, payload FROM workspace WHERE deleted = FALSE LIMIT 1`,
41 ).Scan(&workspace.ResourceID, &payloadBytes); err != nil {
42 if err == sql.ErrNoRows {
43 return nil, nil
44 }
45 return nil, errors.Wrap(err, "failed to get workspace")
46 }
47 payload := &storepb.WorkspacePayload{}
48 if err := common.ProtojsonUnmarshaler.Unmarshal(payloadBytes, payload); err != nil {
49 return nil, errors.Wrap(err, "failed to unmarshal workspace payload")
50 }
51 workspace.Payload = payload
52 return &workspace, nil
53}
54
55// GetWorkspaceByID gets a workspace by its resource ID.
56// Returns (nil, nil) if not found.

Callers 2

GetWorkspaceIDMethod · 0.95
createWorkspaceSliceFunction · 0.80

Calls 3

GetDBMethod · 0.95
ScanMethod · 0.80
UnmarshalMethod · 0.80

Tested by

no test coverage detected