-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample2.go
40 lines (32 loc) · 827 Bytes
/
example2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"net/http"
"golang.org/x/net/context"
"google.golang.org/appengine/datastore"
"github.com/captaincodeman/datastore-mapper"
)
type (
// simple eager iteration and aggregation using counters
example2 struct {
photo *Photo
}
)
func init() {
mapper.RegisterJob(&example2{})
}
func (x *example2) Query(r *http.Request) (*mapper.Query, error) {
q := mapper.NewQuery("photo")
q = q.NamespaceEmpty()
return q, nil
}
// Make creates the entity to load into
func (x *example2) Make() interface{} {
x.photo = new(Photo)
return x.photo
}
// Next processes the next item
func (x *example2) Next(c context.Context, counters mapper.Counters, key *datastore.Key) error {
// the photo instance was loaded from the query by the mapper
counters.Increment(x.photo.Photographer.Name, 1)
return nil
}