MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / createViewOptions

Function createViewOptions

base/collection_view.go:282–362  ·  view source on GitHub ↗

Applies the viewquery options as specified in the params map to the gocb.ViewOptions

(ctx context.Context, params map[string]interface{})

Source from the content-addressed store, hash-verified

280
281// Applies the viewquery options as specified in the params map to the gocb.ViewOptions
282func createViewOptions(ctx context.Context, params map[string]interface{}) (viewOpts *gocb.ViewOptions, err error) {
283
284 viewOpts = &gocb.ViewOptions{}
285 for optionName, optionValue := range params {
286 switch optionName {
287 case ViewQueryParamStale:
288 viewOpts.ScanConsistency = asViewConsistency(ctx, optionValue)
289 case ViewQueryParamReduce:
290 viewOpts.Reduce = asBool(ctx, optionValue)
291 case ViewQueryParamLimit:
292 uintVal, err := normalizeIntToUint(optionValue)
293 if err != nil {
294 WarnfCtx(ctx, "ViewQueryParamLimit error: %v", err)
295 }
296 viewOpts.Limit = uint32(uintVal)
297 case ViewQueryParamDescending:
298 if asBool(ctx, optionValue) == true {
299 viewOpts.Order = gocb.ViewOrderingDescending
300 }
301 case ViewQueryParamSkip:
302 uintVal, err := normalizeIntToUint(optionValue)
303 if err != nil {
304 WarnfCtx(ctx, "ViewQueryParamSkip error: %v", err)
305 }
306 viewOpts.Skip = uint32(uintVal)
307 case ViewQueryParamGroup:
308 viewOpts.Group = asBool(ctx, optionValue)
309 case ViewQueryParamGroupLevel:
310 uintVal, err := normalizeIntToUint(optionValue)
311 if err != nil {
312 WarnfCtx(ctx, "ViewQueryParamGroupLevel error: %v", err)
313 }
314 viewOpts.GroupLevel = uint32(uintVal)
315 case ViewQueryParamKey:
316 viewOpts.Key = optionValue
317 case ViewQueryParamKeys:
318 keys, err := ConvertToEmptyInterfaceSlice(optionValue)
319 if err != nil {
320 return nil, err
321 }
322 viewOpts.Keys = keys
323 case ViewQueryParamStartKey, ViewQueryParamEndKey, ViewQueryParamInclusiveEnd, ViewQueryParamStartKeyDocId, ViewQueryParamEndKeyDocId:
324 // These are dealt with outside of this case statement to build ranges
325 case ViewQueryParamIncludeDocs:
326 // Ignored -- see https://forums.couchbase.com/t/do-the-viewquery-options-omit-include-docs-on-purpose/12399
327 default:
328 return nil, fmt.Errorf("Unexpected view query param: %v. This will be ignored", optionName)
329 }
330 }
331
332 // Range: startkey, endkey, inclusiveend
333 var startKey, endKey interface{}
334 if _, ok := params[ViewQueryParamStartKey]; ok {
335 startKey = params[ViewQueryParamStartKey]
336 }
337 if _, ok := params[ViewQueryParamEndKey]; ok {
338 endKey = params[ViewQueryParamEndKey]
339 }

Calls 6

asViewConsistencyFunction · 0.85
asBoolFunction · 0.85
normalizeIntToUintFunction · 0.85
WarnfCtxFunction · 0.85
ErrorfMethod · 0.80