Documentation ¶
Overview ¶
Example ¶
Here is an example of Haigo's basic usage.
In this case we're loading the "basic-select" query from the "examples/queries.yml" MongoDB query file and then executing it against the "mycol" collection on "mydb".
"Query" simply returns a mgo.Query struct and as such supports all of the expected methods (in this case we're calling Count().
// Dial MongoDB Server sess, _ := mgo.Dial("127.0.0.1") col := sess.DB("mydb").C("mycol") // Load MongoDB Query File hf, _ := LoadQueryFile("examples/queries.yml") params := Params{ "type": "Good", } // Call "basic-select" query. res, _ := hf.Queries["basic-select"].Query(col, params) // Returns mgo.Query struct cnt, _ := res.Count() fmt.Println(cnt)
Output:
Index ¶
- type File
- type Params
- type Query
- func (h *Query) Map(params Params) (interface{}, error)
- func (h *Query) Pipe(col *mgo.Collection, params Params) (*mgo.Pipe, error)
- func (h *Query) Print(params Params) error
- func (h *Query) Query(col *mgo.Collection, params Params) (*mgo.Query, error)
- func (h *Query) String(params Params) (string, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
YAML formatted file with MongoDB Queries.
--- - name: basic-select description: Basic MongoDB Select query: '{"type": {{.type}} }' - name: conditional description: Conditional Query query: '{ "type": "food", "$or": [ { "qty": { "$gt": {{.qty}} } }, { "name": {{.name}} } ] }'
func LoadQueryFile ¶
Reads in Mongo Query File for use with Haigo.
type Query ¶
type Query struct { Name string `yaml:"name"` Description string `yaml:"description,omitempty"` QueryString string `yaml:"query"` // contains filtered or unexported fields }
Click to show internal directories.
Click to hide internal directories.