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

Function parseOrderBy

backend/store/common.go:38–60  ·  view source on GitHub ↗
(orderBy string)

Source from the content-addressed store, hash-verified

36}
37
38func parseOrderBy(orderBy string) ([]*OrderByKey, error) {
39 if orderBy == "" {
40 return nil, nil
41 }
42
43 var result []*OrderByKey
44 re := regexp.MustCompile(`(\w+)\s*(asc|desc)?`)
45 matches := re.FindAllStringSubmatch(orderBy, -1)
46 for _, match := range matches {
47 if len(match) > 3 {
48 return nil, errors.Errorf("invalid order by %q", orderBy)
49 }
50 key := &OrderByKey{
51 Key: match[1],
52 SortOrder: ASC,
53 }
54 if len(match) == 3 && match[2] == "desc" {
55 key.SortOrder = DESC
56 }
57 result = append(result, key)
58 }
59 return result, nil
60}

Callers 7

TestParseOrderByFunction · 0.85
GetDatabaseOrdersFunction · 0.85
GetProjectOrdersFunction · 0.85
GetAuditLogOrdersFunction · 0.85
GetAccessGrantOrdersFunction · 0.85
GetInstanceOrdersFunction · 0.85
GetIssueOrdersFunction · 0.85

Calls 1

ErrorfMethod · 0.80

Tested by 1

TestParseOrderByFunction · 0.68