github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/pkg/couchdb/mango/index.go (about)

     1  package mango
     2  
     3  // An IndexDef is a list of fields to be indexed and an optional partial filter
     4  // for complex and costly requests.
     5  type IndexDef struct {
     6  	Fields        []string `json:"fields"`
     7  	PartialFilter Filter   `json:"partial_filter_selector,omitempty"`
     8  }
     9  
    10  // IndexRequest is a request to be POSTED to create the index
    11  type IndexRequest struct {
    12  	Name  string   `json:"name,omitempty"`
    13  	DDoc  string   `json:"ddoc,omitempty"`
    14  	Index IndexDef `json:"index"`
    15  }
    16  
    17  // Index contains an index request on a specified domain.
    18  type Index struct {
    19  	Doctype string
    20  	Request *IndexRequest
    21  }
    22  
    23  // MakeIndex constructs a new Index
    24  // it lets couchdb defaults for index & designdoc names.
    25  func MakeIndex(doctype, name string, def IndexDef) *Index {
    26  	return &Index{
    27  		Doctype: doctype,
    28  		Request: &IndexRequest{
    29  			DDoc:  name,
    30  			Index: def,
    31  		},
    32  	}
    33  }