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