datastore-mapper icon indicating copy to clipboard operation
datastore-mapper copied to clipboard

Passing parameters to "Query"

Open tim-lebedkov opened this issue 7 years ago • 3 comments

I created a job that should transform entities from one kind to another by getting the values from the request:

`func (x *transform) Query(r *http.Request) (*mapper.Query, error) { c := appengine.NewContext(r)

err := r.ParseForm()
if err != nil {
	return nil, err
}

from := r.Form.Get("from")
to := r.Form.Get("to")

q := mapper.NewQuery(from)
q = q.NamespaceEmpty()
return q, nil

} `

How can I pass this value ("to") to func (x *transform) Next(c context.Context, counters mapper.Counters, key *datastore.Key) error ?

tim-lebedkov avatar Mar 27 '17 18:03 tim-lebedkov

I need to check but I think I made it so the struct is encoded and stored in the datastore so it should be possible to set values on it and then see them in the later stages, as long as they are public / exported and the struct is gob encodable.

CaptainCodeman avatar Mar 27 '17 19:03 CaptainCodeman

it works. I used a private field. It makes sense to document this somehow imho.

tim-lebedkov avatar Mar 28 '17 20:03 tim-lebedkov

Yes definitely, I don't think I ever ended up needing to use it myself so kind of forgot about it :)

Probably makes sense to add something to one of the examples

CaptainCodeman avatar Mar 28 '17 20:03 CaptainCodeman