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


Golang Query.BindVariables方法代码示例

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


在下文中一共展示了Query.BindVariables方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Execute

// Execute routes a non-streaming query.
func (rtr *Router) Execute(ctx context.Context, query *proto.Query) (*mproto.QueryResult, error) {
	if query.BindVariables == nil {
		query.BindVariables = make(map[string]interface{})
	}
	vcursor := newRequestContext(ctx, query, rtr)
	plan := rtr.planner.GetPlan(string(query.Sql))

	switch plan.ID {
	case planbuilder.UpdateEqual:
		return rtr.execUpdateEqual(vcursor, plan)
	case planbuilder.DeleteEqual:
		return rtr.execDeleteEqual(vcursor, plan)
	case planbuilder.InsertSharded:
		return rtr.execInsertSharded(vcursor, plan)
	}

	var err error
	var params *scatterParams
	switch plan.ID {
	case planbuilder.SelectUnsharded, planbuilder.UpdateUnsharded,
		planbuilder.DeleteUnsharded, planbuilder.InsertUnsharded:
		params, err = rtr.paramsUnsharded(vcursor, plan)
	case planbuilder.SelectEqual:
		params, err = rtr.paramsSelectEqual(vcursor, plan)
	case planbuilder.SelectIN:
		params, err = rtr.paramsSelectIN(vcursor, plan)
	case planbuilder.SelectKeyrange:
		params, err = rtr.paramsSelectKeyrange(vcursor, plan)
	case planbuilder.SelectScatter:
		params, err = rtr.paramsSelectScatter(vcursor, plan)
	default:
		return nil, fmt.Errorf("cannot route query: %s: %s", query.Sql, plan.Reason)
	}
	if err != nil {
		return nil, err
	}
	return rtr.scatterConn.ExecuteMulti(
		ctx,
		params.query,
		params.ks,
		params.shardVars,
		query.TabletType,
		NewSafeSession(vcursor.query.Session),
		query.NotInTransaction,
	)
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:47,代码来源:router.go

示例2: StreamExecute

// StreamExecute executes a streaming query.
func (rtr *Router) StreamExecute(ctx context.Context, query *proto.Query, sendReply func(*mproto.QueryResult) error) error {
	if query.BindVariables == nil {
		query.BindVariables = make(map[string]interface{})
	}
	vcursor := newRequestContext(ctx, query, rtr)
	plan := rtr.planner.GetPlan(string(query.Sql))

	var err error
	var params *scatterParams
	switch plan.ID {
	case planbuilder.SelectUnsharded:
		params, err = rtr.paramsUnsharded(vcursor, plan)
	case planbuilder.SelectEqual:
		params, err = rtr.paramsSelectEqual(vcursor, plan)
	case planbuilder.SelectIN:
		params, err = rtr.paramsSelectIN(vcursor, plan)
	case planbuilder.SelectKeyrange:
		params, err = rtr.paramsSelectKeyrange(vcursor, plan)
	case planbuilder.SelectScatter:
		params, err = rtr.paramsSelectScatter(vcursor, plan)
	default:
		return fmt.Errorf("query %q cannot be used for streaming", query.Sql)
	}
	if err != nil {
		return err
	}
	return rtr.scatterConn.StreamExecuteMulti(
		ctx,
		params.query,
		params.ks,
		params.shardVars,
		query.TabletType,
		NewSafeSession(vcursor.query.Session),
		sendReply,
		query.NotInTransaction,
	)
}
开发者ID:pranjal5215,项目名称:vitess,代码行数:38,代码来源:router.go


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