本文整理汇总了Golang中github.com/couchbase/query/datastore.Keyspace.Count方法的典型用法代码示例。如果您正苦于以下问题:Golang Keyspace.Count方法的具体用法?Golang Keyspace.Count怎么用?Golang Keyspace.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbase/query/datastore.Keyspace
的用法示例。
在下文中一共展示了Keyspace.Count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: doPrimaryIndexScan
// Helper function to perform a primary index scan on the given keyspace. Returns a map of
// all primary key names.
func doPrimaryIndexScan(t *testing.T, b datastore.Keyspace) (m map[string]bool, excp errors.Error) {
conn := datastore.NewIndexConnection(&testingContext{t})
m = map[string]bool{}
nitems, excp := b.Count()
if excp != nil {
t.Fatalf("failed to get keyspace count")
return
}
indexers, excp := b.Indexers()
if excp != nil {
t.Fatalf("failed to retrieve indexers")
return
}
pindexes, excp := indexers[0].PrimaryIndexes()
if excp != nil || len(pindexes) < 1 {
t.Fatalf("failed to retrieve primary indexes")
return
}
idx := pindexes[0]
go idx.ScanEntries("", nitems, datastore.UNBOUNDED, nil, conn)
for {
v, ok := <-conn.EntryChannel()
if !ok {
// Channel closed => Scan complete
return
}
m[v.PrimaryKey] = true
}
}
示例2: doIndexScan
// Helper function to scan the primary index of given keyspace with given span
func doIndexScan(t *testing.T, b datastore.Keyspace, span *datastore.Span) (
e []*datastore.IndexEntry, excp errors.Error) {
conn := datastore.NewIndexConnection(&testingContext{t})
e = []*datastore.IndexEntry{}
nitems, excp := b.Count()
if excp != nil {
t.Fatalf("failed to get keyspace count")
return
}
indexers, excp := b.Indexers()
if excp != nil {
t.Fatalf("failed to retrieve indexers")
return
}
idx, excp := indexers[0].IndexByName("#primary")
if excp != nil {
t.Fatalf("failed to retrieve primary index")
return
}
go idx.Scan("", span, false, nitems, datastore.UNBOUNDED, nil, conn)
for {
entry, ok := <-conn.EntryChannel()
if !ok {
return
}
e = append(e, entry)
}
return
}