Пример #1
0
Файл: ws.go Проект: pbochis/api
func ktoi(key *datastore.Key) id {
	return id{
		kind:      key.Kind(),
		stringID:  key.StringID(),
		intID:     key.IntID(),
		appID:     key.AppID(),
		namespace: key.Namespace(),
	}
}
Пример #2
0
func buildKey(req *wcg.Request, key *datastore.Key) *datastore.Key {
	kind := entities.FindKind(key.Kind(), key.Namespace())
	if kind == nil {
		return nil
	}
	if key.Parent() != nil {
		return kind.NewKey(req, key.StringID(), buildKey(req, key.Parent()))
	}
	return kind.NewKey(req, key.StringID(), nil)
}
Пример #3
0
func buildDatastoreKey(key *datastore.Key) (map[string]bigquery.JsonValue, error) {
	if key == nil {
		return map[string]bigquery.JsonValue{
			"namespace": "",
			"app":       "",
			"path":      "",
			"kind":      "",
			"name":      "",
			"id":        0,
		}, nil
	}

	var workKey = key
	var keys []*datastore.Key
	keys = append(keys, key)
	for {
		if workKey.Parent() == nil {
			break
		}
		keys = append(keys, workKey.Parent())
		workKey = workKey.Parent()
	}

	var buf bytes.Buffer
	for i := len(keys) - 1; i >= 0; i-- {
		if buf.Len() > 0 {
			_, err := buf.WriteString(", ")
			if err != nil {
				return map[string]bigquery.JsonValue{}, nil
			}
		}

		key := keys[i]
		if len(key.StringID()) < 1 {
			_, err := buf.WriteString(fmt.Sprintf(`"%s", "%s"`, keys[i].Kind(), keys[i].IntID()))
			if err != nil {
				return map[string]bigquery.JsonValue{}, nil
			}
		} else {
			_, err := buf.WriteString(fmt.Sprintf(`"%s", "%s"`, keys[i].Kind(), keys[i].StringID()))
			if err != nil {
				return map[string]bigquery.JsonValue{}, nil
			}
		}
	}

	return map[string]bigquery.JsonValue{
		"namespace": key.Namespace(),
		"app":       key.AppID(),
		"path":      buf.String(),
		"kind":      key.Kind(),
		"name":      key.StringID(),
		"id":        key.IntID(),
	}, nil
}
Пример #4
0
// Next processes the next item
func (x *example5) Next(c context.Context, counters mapper.Counters, key *datastore.Key) error {
	photo := x.photo
	photo.ID = key.IntID()

	out := &photoOutput{
		Photo:     photo,
		Namespace: key.Namespace(),
	}

	x.encoder.Encode(out)

	return nil
}
Пример #5
0
// dsR2F (DS real-to-fake) converts an SDK Key to a ds.Key
func dsR2F(k *datastore.Key) *ds.Key {
	if k == nil {
		return nil
	}
	aid := k.AppID()
	ns := k.Namespace()

	count := 0
	for nk := k; nk != nil; nk = nk.Parent() {
		count++
	}

	toks := make([]ds.KeyTok, count)

	for ; k != nil; k = k.Parent() {
		count--
		toks[count].Kind = k.Kind()
		toks[count].StringID = k.StringID()
		toks[count].IntID = k.IntID()
	}
	return ds.NewKeyToks(aid, ns, toks)
}