Skip to content

Commit

Permalink
Add sorted to viewOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
flimzy committed May 20, 2024
1 parent 0876abe commit c0049e5
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 4 deletions.
23 changes: 23 additions & 0 deletions x/sqlite/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,23 @@ func toBool(in interface{}) (value bool, ok bool) {
}
}

func (o optsMap) sorted() (bool, error) {
param, ok := o["sorted"]
if !ok {
return true, nil
}
v, ok := toBool(param)
if !ok {
return false, &internal.Error{Status: http.StatusBadRequest, Message: fmt.Sprintf("invalid value for 'sorted': %v", param)}
}
if _, ok := o["descending"]; ok {
// If descending is set to anything, then sorted must be true.
// Error handling for invalid descending values is handled elsewhere.
return true, nil
}
return v, nil
}

func (o optsMap) descending() (bool, error) {
param, ok := o["descending"]
if !ok {
Expand Down Expand Up @@ -556,6 +573,7 @@ type viewOptions struct {
startkeyDocID string
key string
keys []string
sorted bool
}

func (o optsMap) viewOptions(view string) (*viewOptions, error) {
Expand Down Expand Up @@ -634,6 +652,10 @@ func (o optsMap) viewOptions(view string) (*viewOptions, error) {
if err != nil {
return nil, err
}
sorted, err := o.sorted()
if err != nil {
return nil, err
}

return &viewOptions{
view: view,
Expand All @@ -655,5 +677,6 @@ func (o optsMap) viewOptions(view string) (*viewOptions, error) {
startkeyDocID: startkeyDocID,
key: key,
keys: keys,
sorted: sorted,
}, nil
}
Loading

0 comments on commit c0049e5

Please sign in to comment.