本文整理匯總了Golang中github.com/luci/gae/service/datastore.PropertyMap.SetMeta方法的典型用法代碼示例。如果您正苦於以下問題:Golang PropertyMap.SetMeta方法的具體用法?Golang PropertyMap.SetMeta怎麽用?Golang PropertyMap.SetMeta使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/luci/gae/service/datastore.PropertyMap
的用法示例。
在下文中一共展示了PropertyMap.SetMeta方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestBasicDatastore
//.........這裏部分代碼省略.........
q := datastore.NewQuery("TestStruct")
ds.Run(q, func(ts *TestStruct) {
So(*ts, ShouldResemble, orig)
})
count, err := ds.Count(q)
So(err, ShouldBeNil)
So(count, ShouldEqual, 1)
})
Convey("Can project", func() {
q := datastore.NewQuery("TestStruct").Project("ValueS")
rslts := []datastore.PropertyMap{}
So(ds.GetAll(q, &rslts), ShouldBeNil)
So(rslts, ShouldResemble, []datastore.PropertyMap{
{
"$key": {mpNI(ds.KeyForObj(&orig))},
"ValueS": {mp("hello")},
},
{
"$key": {mpNI(ds.KeyForObj(&orig))},
"ValueS": {mp("world")},
},
})
q = datastore.NewQuery("TestStruct").Project("ValueBS")
rslts = []datastore.PropertyMap{}
So(ds.GetAll(q, &rslts), ShouldBeNil)
So(rslts, ShouldResemble, []datastore.PropertyMap{
{
"$key": {mpNI(ds.KeyForObj(&orig))},
"ValueBS": {mp("allo")},
},
{
"$key": {mpNI(ds.KeyForObj(&orig))},
"ValueBS": {mp("hello")},
},
{
"$key": {mpNI(ds.KeyForObj(&orig))},
"ValueBS": {mp("world")},
},
{
"$key": {mpNI(ds.KeyForObj(&orig))},
"ValueBS": {mp("zurple")},
},
})
count, err := ds.Count(q)
So(err, ShouldBeNil)
So(count, ShouldEqual, 4)
})
})
Convey("Can Put/Get (time)", func() {
// time comparisons in Go are wonky, so this is pulled out
pm := datastore.PropertyMap{
"$key": {mpNI(ds.NewKey("Something", "value", 0, nil))},
"Time": {
mp(time.Date(1938, time.January, 1, 1, 1, 1, 1, time.UTC)),
mp(time.Time{}),
},
}
So(ds.Put(&pm), ShouldBeNil)
rslt := datastore.PropertyMap{}
rslt.SetMeta("key", ds.KeyForObj(pm))
So(ds.Get(&rslt), ShouldBeNil)
So(pm["Time"][0].Value(), ShouldResemble, rslt["Time"][0].Value())
q := datastore.NewQuery("Something").Project("Time")
all := []datastore.PropertyMap{}
So(ds.GetAll(q, &all), ShouldBeNil)
So(len(all), ShouldEqual, 2)
prop := all[0]["Time"][0]
So(prop.Type(), ShouldEqual, datastore.PTInt)
tval, err := prop.Project(datastore.PTTime)
So(err, ShouldBeNil)
So(tval, ShouldResemble, time.Time{})
tval, err = all[1]["Time"][0].Project(datastore.PTTime)
So(err, ShouldBeNil)
So(tval, ShouldResemble, pm["Time"][0].Value())
ent := datastore.PropertyMap{
"$key": {mpNI(ds.MakeKey("Something", "value"))},
}
So(ds.Get(&ent), ShouldBeNil)
So(ent["Time"], ShouldResemble, pm["Time"])
})
Convey("memcache: Set (nil) is the same as Set ([]byte{})", func() {
So(mc.Set(mc.NewItem("bob")), ShouldBeNil) // normally would panic because Value is nil
bob, err := mc.Get("bob")
So(err, ShouldBeNil)
So(bob.Value(), ShouldResemble, []byte{})
})
})
}
示例2: TestDatastoreSingleReadWriter
func TestDatastoreSingleReadWriter(t *testing.T) {
t.Parallel()
Convey("Datastore single reads and writes", t, func() {
c := Use(context.Background())
ds := dsS.Get(c)
So(ds, ShouldNotBeNil)
Convey("getting objects that DNE is an error", func() {
So(ds.Get(&Foo{Id: 1}), ShouldEqual, dsS.ErrNoSuchEntity)
})
Convey("bad namespaces fail", func() {
_, err := infoS.Get(c).Namespace("$$blzyall")
So(err.Error(), ShouldContainSubstring, "namespace \"$$blzyall\" does not match")
})
Convey("Can Put stuff", func() {
// with an incomplete key!
f := &Foo{Val: 10}
So(ds.Put(f), ShouldBeNil)
k := ds.KeyForObj(f)
So(k.String(), ShouldEqual, "/Foo,1")
Convey("and Get it back", func() {
newFoo := &Foo{Id: 1}
So(ds.Get(newFoo), ShouldBeNil)
So(newFoo, ShouldResemble, f)
Convey("but it's hidden from a different namespace", func() {
c, err := infoS.Get(c).Namespace("whombat")
So(err, ShouldBeNil)
ds = dsS.Get(c)
So(ds.Get(f), ShouldEqual, dsS.ErrNoSuchEntity)
})
Convey("and we can Delete it", func() {
So(ds.Delete(k), ShouldBeNil)
So(ds.Get(newFoo), ShouldEqual, dsS.ErrNoSuchEntity)
})
})
Convey("Deleteing with a bogus key is bad", func() {
So(ds.Delete(ds.NewKey("Foo", "wat", 100, nil)), ShouldEqual, dsS.ErrInvalidKey)
})
Convey("Deleteing a DNE entity is fine", func() {
So(ds.Delete(ds.NewKey("Foo", "wat", 0, nil)), ShouldBeNil)
})
Convey("with multiple puts", func() {
So(testGetMeta(c, k), ShouldEqual, 1)
foos := make([]Foo, 10)
for i := range foos {
foos[i].Val = 10
foos[i].Parent = k
}
So(ds.PutMulti(foos), ShouldBeNil)
So(testGetMeta(c, k), ShouldEqual, 11)
keys := make([]dsS.Key, len(foos))
for i, f := range foos {
keys[i] = ds.KeyForObj(&f)
}
Convey("ensure that group versions persist across deletes", func() {
So(ds.DeleteMulti(append(keys, k)), ShouldBeNil)
// TODO(riannucci): replace with a Count query instead of this cast
/*
ents := ds.(*dsImpl).data.head.GetCollection("ents:")
num, _ := ents.GetTotals()
// /__entity_root_ids__,Foo
// /Foo,1/__entity_group__,1
// /Foo,1/__entity_group_ids__,1
So(num, ShouldEqual, 3)
*/
So(testGetMeta(c, k), ShouldEqual, 22)
So(ds.Put(&Foo{Id: 1}), ShouldBeNil)
So(testGetMeta(c, k), ShouldEqual, 23)
})
Convey("can Get", func() {
vals := make([]dsS.PropertyMap, len(keys))
for i := range vals {
vals[i] = dsS.PropertyMap{}
vals[i].SetMeta("key", keys[i])
}
So(ds.GetMulti(vals), ShouldBeNil)
for i, val := range vals {
So(val, ShouldResemble, dsS.PropertyMap{
"Val": {dsS.MkProperty(10)},
"$key": {dsS.MkPropertyNI(keys[i])},
})
}
})
//.........這裏部分代碼省略.........
示例3: TestDatastoreSingleReadWriter
//.........這裏部分代碼省略.........
for i := range foos {
foos[i].Val = 10
foos[i].Parent = k
}
So(ds.PutMulti(foos), ShouldBeNil)
So(testGetMeta(c, k), ShouldEqual, 11)
keys := make([]*dsS.Key, len(foos))
for i, f := range foos {
keys[i] = ds.KeyForObj(&f)
}
Convey("ensure that group versions persist across deletes", func() {
So(ds.DeleteMulti(append(keys, k)), ShouldBeNil)
ds.Testable().CatchupIndexes()
count := 0
So(ds.Run(dsS.NewQuery(""), func(_ *dsS.Key) {
count++
}), ShouldBeNil)
So(count, ShouldEqual, 3)
So(testGetMeta(c, k), ShouldEqual, 22)
So(ds.Put(&Foo{ID: 1}), ShouldBeNil)
So(testGetMeta(c, k), ShouldEqual, 23)
})
Convey("can Get", func() {
vals := make([]dsS.PropertyMap, len(keys))
for i := range vals {
vals[i] = dsS.PropertyMap{}
So(vals[i].SetMeta("key", keys[i]), ShouldBeTrue)
}
So(ds.GetMulti(vals), ShouldBeNil)
for i, val := range vals {
So(val, ShouldResemble, dsS.PropertyMap{
"Val": {dsS.MkProperty(10)},
"$key": {dsS.MkPropertyNI(keys[i])},
})
}
})
})
Convey("allocating ids prevents their use", func() {
start, err := ds.AllocateIDs(ds.MakeKey("Foo", 0), 100)
So(err, ShouldBeNil)
So(start, ShouldEqual, 2)
f := &Foo{Val: 10}
So(ds.Put(f), ShouldBeNil)
k := ds.KeyForObj(f)
So(k.String(), ShouldEqual, "dev~app::/Foo,102")
})
})
Convey("implements DSTransactioner", func() {
Convey("Put", func() {
f := &Foo{Val: 10}
So(ds.Put(f), ShouldBeNil)
k := ds.KeyForObj(f)
So(k.String(), ShouldEqual, "dev~app::/Foo,1")
示例4: TestBasicDatastore
func TestBasicDatastore(t *testing.T) {
t.Parallel()
Convey("basic", t, func() {
ctx, closer, err := aetest.NewContext()
So(err, ShouldBeNil)
defer closer()
ctx = Use(ctx)
ds := dstore.Get(ctx)
Convey("Can Put/Get", func() {
orig := TestStruct{
ValueI: []int64{1, 7, 946688461000000, 996688461000000},
ValueB: []bool{true, false},
ValueS: []string{"hello", "world"},
ValueF: []float64{1.0, 7.0, 946688461000000.0, 996688461000000.0},
ValueBS: [][]byte{
[]byte("allo"),
[]byte("hello"),
[]byte("world"),
[]byte("zurple"),
},
ValueK: []dstore.Key{
ds.NewKey("Something", "Cool", 0, nil),
ds.NewKey("Something", "", 1, nil),
ds.NewKey("Something", "Recursive", 0,
ds.NewKey("Parent", "", 2, nil)),
},
ValueBK: []blobstore.Key{"bellow", "hello"},
ValueGP: []dstore.GeoPoint{
{Lat: 120.7, Lng: 95.5},
},
}
So(ds.Put(&orig), ShouldBeNil)
ret := TestStruct{ID: orig.ID}
So(ds.Get(&ret), ShouldBeNil)
So(ret, ShouldResemble, orig)
// can't be sure the indexes have caught up... so sleep
time.Sleep(time.Second)
Convey("Can query", func() {
ds.Run(ds.NewQuery("TestStruct"), func(ts *TestStruct, _ dstore.CursorCB) bool {
So(*ts, ShouldResemble, orig)
return true
})
})
Convey("Can project", func() {
q := ds.NewQuery("TestStruct").Project("ValueS")
rslts := []dstore.PropertyMap{}
So(ds.GetAll(q, &rslts), ShouldBeNil)
So(rslts, ShouldResemble, []dstore.PropertyMap{
{
"$key": {mpNI(ds.KeyForObj(&orig))},
"ValueS": {mp("hello")},
},
{
"$key": {mpNI(ds.KeyForObj(&orig))},
"ValueS": {mp("world")},
},
})
q = ds.NewQuery("TestStruct").Project("ValueBS")
rslts = []dstore.PropertyMap{}
So(ds.GetAll(q, &rslts), ShouldBeNil)
So(rslts, ShouldResemble, []dstore.PropertyMap{
{
"$key": {mpNI(ds.KeyForObj(&orig))},
"ValueBS": {mp("allo")},
},
{
"$key": {mpNI(ds.KeyForObj(&orig))},
"ValueBS": {mp("hello")},
},
{
"$key": {mpNI(ds.KeyForObj(&orig))},
"ValueBS": {mp("world")},
},
{
"$key": {mpNI(ds.KeyForObj(&orig))},
"ValueBS": {mp("zurple")},
},
})
})
})
Convey("Can Put/Get (time)", func() {
// time comparisons in Go are wonky, so this is pulled out
pm := dstore.PropertyMap{
"$key": {mpNI(ds.NewKey("Something", "value", 0, nil))},
"Time": {mp(time.Date(1938, time.January, 1, 1, 1, 1, 1, time.UTC))},
}
So(ds.Put(&pm), ShouldBeNil)
rslt := dstore.PropertyMap{}
rslt.SetMeta("key", ds.KeyForObj(pm))
So(ds.Get(&rslt), ShouldBeNil)
//.........這裏部分代碼省略.........