本文整理汇总了Golang中github.com/luci/gae/service/datastore.IndexDefinition.SortBy方法的典型用法代码示例。如果您正苦于以下问题:Golang IndexDefinition.SortBy方法的具体用法?Golang IndexDefinition.SortBy怎么用?Golang IndexDefinition.SortBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/luci/gae/service/datastore.IndexDefinition
的用法示例。
在下文中一共展示了IndexDefinition.SortBy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCompoundIndexes
func TestCompoundIndexes(t *testing.T) {
t.Parallel()
idxKey := func(def dsS.IndexDefinition) string {
So(def, ShouldNotBeNil)
return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable()))
}
numItms := func(c *memCollection) uint64 {
ret, _ := c.GetTotals()
return ret
}
Convey("Test Compound indexes", t, func() {
type Model struct {
ID int64 `gae:"$id"`
Field1 []string
Field2 []int64
}
c := Use(context.Background())
ds := dsS.Get(c)
t := ds.Testable().(*dsImpl)
head := t.data.head
So(ds.Put(&Model{1, []string{"hello", "world"}, []int64{10, 11}}), ShouldBeNil)
idx := dsS.IndexDefinition{
Kind: "Model",
SortBy: []dsS.IndexColumn{
{Property: "Field2"},
},
}
coll := head.GetCollection(idxKey(idx))
So(coll, ShouldNotBeNil)
So(numItms(coll), ShouldEqual, 2)
idx.SortBy[0].Property = "Field1"
coll = head.GetCollection(idxKey(idx))
So(coll, ShouldNotBeNil)
So(numItms(coll), ShouldEqual, 2)
idx.SortBy = append(idx.SortBy, dsS.IndexColumn{Property: "Field1"})
So(head.GetCollection(idxKey(idx)), ShouldBeNil)
t.AddIndexes(&idx)
coll = head.GetCollection(idxKey(idx))
So(coll, ShouldNotBeNil)
So(numItms(coll), ShouldEqual, 4)
})
}
示例2: TestSerializationReadMisc
//.........这里部分代码省略.........
Convey("trunc 1", func() {
p, err := ReadProperty(buf, WithContext, "", "")
So(err, ShouldEqual, io.EOF)
So(p.Type(), ShouldEqual, ds.PTNull)
So(p.Value(), ShouldBeNil)
})
Convey("trunc (PTBytes)", func() {
buf.WriteByte(byte(ds.PTBytes))
_, err := ReadProperty(buf, WithContext, "", "")
So(err, ShouldEqual, io.EOF)
})
Convey("trunc (PTBlobKey)", func() {
buf.WriteByte(byte(ds.PTBlobKey))
_, err := ReadProperty(buf, WithContext, "", "")
So(err, ShouldEqual, io.EOF)
})
Convey("invalid type", func() {
buf.WriteByte(byte(ds.PTUnknown + 1))
_, err := ReadProperty(buf, WithContext, "", "")
So(err, ShouldErrLike, "unknown type!")
})
})
Convey("ReadPropertyMap", func() {
buf := mkBuf(nil)
Convey("trunc 1", func() {
_, err := ReadPropertyMap(buf, WithContext, "", "")
So(err, ShouldEqual, io.EOF)
})
Convey("too many rows", func() {
cmpbin.WriteUint(buf, 1000000)
_, err := ReadPropertyMap(buf, WithContext, "", "")
So(err, ShouldErrLike, "huge number of rows")
})
Convey("trunc 2", func() {
cmpbin.WriteUint(buf, 10)
_, err := ReadPropertyMap(buf, WithContext, "", "")
So(err, ShouldEqual, io.EOF)
})
Convey("trunc 3", func() {
cmpbin.WriteUint(buf, 10)
cmpbin.WriteString(buf, "ohai")
_, err := ReadPropertyMap(buf, WithContext, "", "")
So(err, ShouldEqual, io.EOF)
})
Convey("too many values", func() {
cmpbin.WriteUint(buf, 10)
cmpbin.WriteString(buf, "ohai")
cmpbin.WriteUint(buf, 100000)
_, err := ReadPropertyMap(buf, WithContext, "", "")
So(err, ShouldErrLike, "huge number of properties")
})
Convey("trunc 4", func() {
cmpbin.WriteUint(buf, 10)
cmpbin.WriteString(buf, "ohai")
cmpbin.WriteUint(buf, 10)
_, err := ReadPropertyMap(buf, WithContext, "", "")
So(err, ShouldEqual, io.EOF)
})
})
Convey("IndexDefinition", func() {
id := ds.IndexDefinition{Kind: "kind"}
data := ToBytes(*id.PrepForIdxTable())
newID, err := ReadIndexDefinition(mkBuf(data))
So(err, ShouldBeNil)
So(newID.Flip(), ShouldResemble, id.Normalize())
id.SortBy = append(id.SortBy, ds.IndexColumn{Property: "prop"})
data = ToBytes(*id.PrepForIdxTable())
newID, err = ReadIndexDefinition(mkBuf(data))
So(err, ShouldBeNil)
So(newID.Flip(), ShouldResemble, id.Normalize())
id.SortBy = append(id.SortBy, ds.IndexColumn{Property: "other", Direction: ds.DESCENDING})
id.Ancestor = true
data = ToBytes(*id.PrepForIdxTable())
newID, err = ReadIndexDefinition(mkBuf(data))
So(err, ShouldBeNil)
So(newID.Flip(), ShouldResemble, id.Normalize())
// invalid
id.SortBy = append(id.SortBy, ds.IndexColumn{Property: "", Direction: ds.DESCENDING})
data = ToBytes(*id.PrepForIdxTable())
newID, err = ReadIndexDefinition(mkBuf(data))
So(err, ShouldBeNil)
So(newID.Flip(), ShouldResemble, id.Normalize())
Convey("too many", func() {
id := ds.IndexDefinition{Kind: "wat"}
for i := 0; i < MaxIndexColumns+1; i++ {
id.SortBy = append(id.SortBy, ds.IndexColumn{Property: "Hi", Direction: ds.ASCENDING})
}
data := ToBytes(*id.PrepForIdxTable())
newID, err = ReadIndexDefinition(mkBuf(data))
So(err, ShouldErrLike, "over 64 sort orders")
})
})
})
}