本文整理匯總了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
}