當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。