Skip to content

Commit

Permalink
Add att_encoduing_info to viewOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
flimzy committed May 20, 2024
1 parent c0049e5 commit d3dcfba
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 42 deletions.
98 changes: 58 additions & 40 deletions x/sqlite/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,18 @@ func (o optsMap) updateSeq() (bool, error) {
return v, nil
}

func (o optsMap) attEncodingInfo() (bool, error) {
param, ok := o["att_encoding_info"]
if !ok {
return false, nil
}
v, ok := toBool(param)
if !ok {
return false, &internal.Error{Status: http.StatusBadRequest, Message: fmt.Sprintf("invalid value for 'att_encoding_info': %v", param)}
}
return v, nil
}

// buildWhere returns WHERE conditions based on the provided configuration
// arguments, and may append to args as needed.
func (v viewOptions) buildWhere(args *[]any) []string {
Expand Down Expand Up @@ -554,26 +566,27 @@ func (v viewOptions) buildWhere(args *[]any) []string {
//
// See https://docs.couchdb.org/en/stable/api/ddoc/views.html#api-ddoc-view
type viewOptions struct {
view string
limit int64
skip int64
descending bool
includeDocs bool
conflicts bool
reduce *bool
group bool
groupLevel uint64
endkey string
startkey string
inclusiveEnd bool
attachments bool
update string
updateSeq bool
endkeyDocID string
startkeyDocID string
key string
keys []string
sorted bool
view string
limit int64
skip int64
descending bool
includeDocs bool
conflicts bool
reduce *bool
group bool
groupLevel uint64
endkey string
startkey string
inclusiveEnd bool
attachments bool
update string
updateSeq bool
endkeyDocID string
startkeyDocID string
key string
keys []string
sorted bool
attEncodingInfo bool
}

func (o optsMap) viewOptions(view string) (*viewOptions, error) {
Expand Down Expand Up @@ -656,27 +669,32 @@ func (o optsMap) viewOptions(view string) (*viewOptions, error) {
if err != nil {
return nil, err
}
attEncodingInfo, err := o.attEncodingInfo()
if err != nil {
return nil, err
}

return &viewOptions{
view: view,
limit: limit,
skip: skip,
descending: descending,
includeDocs: includeDocs,
conflicts: conflicts,
reduce: reduce,
group: group,
groupLevel: groupLevel,
endkey: endkey,
startkey: startkey,
inclusiveEnd: inclusiveEnd,
attachments: attachments,
update: update,
updateSeq: updateSeq,
endkeyDocID: endkeyDocID,
startkeyDocID: startkeyDocID,
key: key,
keys: keys,
sorted: sorted,
view: view,
limit: limit,
skip: skip,
descending: descending,
includeDocs: includeDocs,
conflicts: conflicts,
reduce: reduce,
group: group,
groupLevel: groupLevel,
endkey: endkey,
startkey: startkey,
inclusiveEnd: inclusiveEnd,
attachments: attachments,
update: update,
updateSeq: updateSeq,
endkeyDocID: endkeyDocID,
startkeyDocID: startkeyDocID,
key: key,
keys: keys,
sorted: sorted,
attEncodingInfo: attEncodingInfo,
}, nil
}
28 changes: 26 additions & 2 deletions x/sqlite/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,9 +781,33 @@ func Test_viewOptions(t *testing.T) {
wantStatus: http.StatusBadRequest,
})

/*
att_encoding_info (boolean) – Include encoding information in attachment stubs if include_docs is true and the particular attachment is compressed. Ignored if include_docs isn’t true. Default is false.
tests.Add("att_encoding_info: bool", test{
options: kivik.Param("att_encoding_info", true),
want: &viewOptions{
limit: -1,
inclusiveEnd: true,
update: "true",
sorted: true,
attEncodingInfo: true,
},
})
tests.Add("att_encoding_info: valid string", test{
options: kivik.Param("att_encoding_info", "true"),
want: &viewOptions{
limit: -1,
inclusiveEnd: true,
update: "true",
sorted: true,
attEncodingInfo: true,
},
})
tests.Add("att_encoding_info: invalid string", test{
options: kivik.Param("att_encoding_info", "chicken"),
wantErr: "invalid value for 'att_encoding_info': chicken",
wantStatus: http.StatusBadRequest,
})

/*
stable (boolean) – Whether or not the view results should be returned from a stable set of shards. Default is false.
*/

Expand Down

0 comments on commit d3dcfba

Please sign in to comment.