From d3dcfbade8e52eaf03fb2804b4c3765a2e62e0c5 Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Mon, 20 May 2024 14:58:05 +0200 Subject: [PATCH] Add att_encoduing_info to viewOptions --- x/sqlite/options.go | 98 ++++++++++++++++++++++++---------------- x/sqlite/options_test.go | 28 +++++++++++- 2 files changed, 84 insertions(+), 42 deletions(-) diff --git a/x/sqlite/options.go b/x/sqlite/options.go index f1d5d1e0d..c21f62c7f 100644 --- a/x/sqlite/options.go +++ b/x/sqlite/options.go @@ -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 { @@ -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) { @@ -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 } diff --git a/x/sqlite/options_test.go b/x/sqlite/options_test.go index 8203d857a..36db1fab6 100644 --- a/x/sqlite/options_test.go +++ b/x/sqlite/options_test.go @@ -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. */