本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/internal/client.Txn.Scan方法的典型用法代码示例。如果您正苦于以下问题:Golang Txn.Scan方法的具体用法?Golang Txn.Scan怎么用?Golang Txn.Scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/pkg/internal/client.Txn
的用法示例。
在下文中一共展示了Txn.Scan方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AllRangeDescriptors
// AllRangeDescriptors fetches all meta2 RangeDescriptor using the given txn.
func AllRangeDescriptors(txn *client.Txn) ([]roachpb.RangeDescriptor, error) {
// TODO(dan): Iterate with some batch size.
rows, err := txn.Scan(keys.Meta2Prefix, keys.MetaMax, 0)
if err != nil {
return nil, errors.Wrap(err, "unable to scan range descriptors")
}
rangeDescs := make([]roachpb.RangeDescriptor, len(rows))
for i, row := range rows {
if err := row.ValueProto(&rangeDescs[i]); err != nil {
return nil, errors.Wrapf(err, "%s: unable to unmarshal range descriptor", row.Key)
}
}
return rangeDescs, nil
}
示例2: scanCmd
// scanCmd reads the values from the db from [key, endKey).
func scanCmd(c *cmd, txn *client.Txn, t *testing.T) error {
rows, err := txn.Scan(c.getKey(), c.getEndKey(), 0)
if err != nil {
return err
}
var vals []string
keyPrefix := []byte(fmt.Sprintf("%d.", c.historyIdx))
for _, kv := range rows {
key := bytes.TrimPrefix(kv.Key, keyPrefix)
c.env[string(key)] = kv.ValueInt()
vals = append(vals, fmt.Sprintf("%d", kv.ValueInt()))
}
c.debug = fmt.Sprintf("[%s]", strings.Join(vals, " "))
return nil
}
示例3: allSQLDescriptors
func allSQLDescriptors(txn *client.Txn) ([]sqlbase.Descriptor, error) {
startKey := roachpb.Key(keys.MakeTablePrefix(keys.DescriptorTableID))
endKey := startKey.PrefixEnd()
// TODO(dan): Iterate with some batch size.
rows, err := txn.Scan(startKey, endKey, 0)
if err != nil {
return nil, errors.Wrap(err, "unable to scan SQL descriptors")
}
sqlDescs := make([]sqlbase.Descriptor, len(rows))
for i, row := range rows {
if err := row.ValueProto(&sqlDescs[i]); err != nil {
return nil, errors.Wrapf(err, "%s: unable to unmarshal SQL descriptor", row.Key)
}
}
return sqlDescs, nil
}