本文整理汇总了Golang中github.com/youtube/vitess/go/vt/vtgate/planbuilder.VCursor类的典型用法代码示例。如果您正苦于以下问题:Golang VCursor类的具体用法?Golang VCursor怎么用?Golang VCursor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VCursor类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Map2
// Map2 is for a non-unique vindex.
func (lkp *lookup) Map2(vcursor planbuilder.VCursor, ids []interface{}) ([][][]byte, error) {
out := make([][][]byte, 0, len(ids))
bq := &tproto.BoundQuery{
Sql: lkp.sel,
}
for _, id := range ids {
bq.BindVariables = map[string]interface{}{
lkp.From: id,
}
result, err := vcursor.Execute(bq)
if err != nil {
return nil, fmt.Errorf("lookup.Map: %v", err)
}
var ksids [][]byte
for _, row := range result.Rows {
num, err := getNumber(row[0].ToNative())
if err != nil {
return nil, fmt.Errorf("lookup.Map: %v", err)
}
ksids = append(ksids, vhash(num))
}
out = append(out, ksids)
}
return out, nil
}
示例2: Map1
// Map1 is for a unique vindex.
func (lkp *lookup) Map1(vcursor planbuilder.VCursor, ids []interface{}) ([][]byte, error) {
out := make([][]byte, 0, len(ids))
bq := &tproto.BoundQuery{
Sql: lkp.sel,
}
for _, id := range ids {
bq.BindVariables = map[string]interface{}{
lkp.From: id,
}
result, err := vcursor.Execute(bq)
if err != nil {
return nil, fmt.Errorf("lookup.Map: %v", err)
}
if len(result.Rows) == 0 {
out = append(out, []byte{})
continue
}
if len(result.Rows) != 1 {
return nil, fmt.Errorf("lookup.Map: unexpected multiple results from vindex %s: %v", lkp.Table, id)
}
num, err := getNumber(result.Rows[0][0].ToNative())
if err != nil {
return nil, fmt.Errorf("lookup.Map: %v", err)
}
out = append(out, vhash(num))
}
return out, nil
}
示例3: Delete
// Delete deletes the entry from the vindex table.
func (vind *HashAuto) Delete(vcursor planbuilder.VCursor, ids []interface{}, _ []byte) error {
bq := &tproto.BoundQuery{
Sql: vind.del,
BindVariables: map[string]interface{}{
vind.Column: ids,
},
}
if _, err := vcursor.Execute(bq); err != nil {
return fmt.Errorf("hash.Delete: %v", err)
}
return nil
}
示例4: Create
// Create reserves the id by inserting it into the vindex table.
func (vind *HashAuto) Create(vcursor planbuilder.VCursor, id interface{}) error {
bq := &tproto.BoundQuery{
Sql: vind.ins,
BindVariables: map[string]interface{}{
vind.Column: id,
},
}
if _, err := vcursor.Execute(bq); err != nil {
return fmt.Errorf("hash.Create: %v", err)
}
return nil
}
示例5: Generate
// Generate generates a new id by using the autoinc of the vindex table.
func (vind *HashAuto) Generate(vcursor planbuilder.VCursor) (id int64, err error) {
bq := &tproto.BoundQuery{
Sql: vind.ins,
BindVariables: map[string]interface{}{
vind.Column: nil,
},
}
result, err := vcursor.Execute(bq)
if err != nil {
return 0, fmt.Errorf("hash.Generate: %v", err)
}
return int64(result.InsertID), err
}
示例6: Delete
// Delete deletes the association between ids and ksid.
func (lkp *lookup) Delete(vcursor planbuilder.VCursor, ids []interface{}, ksid []byte) error {
val, err := vunhash(ksid)
if err != nil {
return fmt.Errorf("lookup.Delete: %v", err)
}
bq := &tproto.BoundQuery{
Sql: lkp.del,
BindVariables: map[string]interface{}{
lkp.From: ids,
lkp.To: val,
},
}
if _, err := vcursor.Execute(bq); err != nil {
return fmt.Errorf("lookup.Delete: %v", err)
}
return nil
}
示例7: Create
// Create creates an association between id and ksid by inserting a row in the vindex table.
func (lkp *lookup) Create(vcursor planbuilder.VCursor, id interface{}, ksid key.KeyspaceId) error {
val, err := vunhash(ksid)
if err != nil {
return fmt.Errorf("lookup.Create: %v", err)
}
bq := &tproto.BoundQuery{
Sql: lkp.ins,
BindVariables: map[string]interface{}{
lkp.From: id,
lkp.To: val,
},
}
if _, err := vcursor.Execute(bq); err != nil {
return fmt.Errorf("lookup.Create: %v", err)
}
return nil
}
示例8: Generate
// Generate generates an id and associates the ksid to the new id.
func (lkp *lookup) Generate(vcursor planbuilder.VCursor, ksid []byte) (id int64, err error) {
val, err := vunhash(ksid)
if err != nil {
return 0, fmt.Errorf("lookup.Generate: %v", err)
}
bq := &tproto.BoundQuery{
Sql: lkp.ins,
BindVariables: map[string]interface{}{
lkp.From: nil,
lkp.To: val,
},
}
result, err := vcursor.Execute(bq)
if err != nil {
return 0, fmt.Errorf("lookup.Generate: %v", err)
}
return int64(result.InsertID), err
}
示例9: Verify
// Verify returns true if id maps to ksid.
func (lkp *lookup) Verify(vcursor planbuilder.VCursor, id interface{}, ksid []byte) (bool, error) {
val, err := vunhash(ksid)
if err != nil {
return false, fmt.Errorf("lookup.Verify: %v", err)
}
bq := &tproto.BoundQuery{
Sql: lkp.ver,
BindVariables: map[string]interface{}{
lkp.From: id,
lkp.To: val,
},
}
result, err := vcursor.Execute(bq)
if err != nil {
return false, fmt.Errorf("lookup.Verify: %v", err)
}
if len(result.Rows) == 0 {
return false, nil
}
return true, nil
}