当前位置: 首页>>代码示例>>Golang>>正文


Golang VCursor.Execute方法代码示例

本文整理汇总了Golang中github.com/youtube/vitess/go/vt/vtgate/planbuilder.VCursor.Execute方法的典型用法代码示例。如果您正苦于以下问题:Golang VCursor.Execute方法的具体用法?Golang VCursor.Execute怎么用?Golang VCursor.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/youtube/vitess/go/vt/vtgate/planbuilder.VCursor的用法示例。


在下文中一共展示了VCursor.Execute方法的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
}
开发者ID:BobbWu,项目名称:vitess,代码行数:26,代码来源:lookup_hash.go

示例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
}
开发者ID:BobbWu,项目名称:vitess,代码行数:29,代码来源:lookup_hash.go

示例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
}
开发者ID:BobbWu,项目名称:vitess,代码行数:13,代码来源:hash.go

示例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
}
开发者ID:BobbWu,项目名称:vitess,代码行数:13,代码来源:hash.go

示例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
}
开发者ID:BobbWu,项目名称:vitess,代码行数:14,代码来源:hash.go

示例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
}
开发者ID:BobbWu,项目名称:vitess,代码行数:18,代码来源:lookup_hash.go

示例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
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:18,代码来源:lookup_hash.go

示例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
}
开发者ID:BobbWu,项目名称:vitess,代码行数:19,代码来源:lookup_hash.go

示例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
}
开发者ID:BobbWu,项目名称:vitess,代码行数:22,代码来源:lookup_hash.go


注:本文中的github.com/youtube/vitess/go/vt/vtgate/planbuilder.VCursor.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。