本文整理汇总了Golang中github.com/youtube/vitess/go/vt/tabletserver/querytypes.Proto3ToBindVariables函数的典型用法代码示例。如果您正苦于以下问题:Golang Proto3ToBindVariables函数的具体用法?Golang Proto3ToBindVariables怎么用?Golang Proto3ToBindVariables使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Proto3ToBindVariables函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: StreamExecute
// StreamExecute is part of tabletconn.TabletConn
// We need to copy the bind variables as tablet server will change them.
func (itc *internalTabletConn) StreamExecute(ctx context.Context, query string, bindVars map[string]interface{}, transactionID int64) (<-chan *sqltypes.Result, tabletconn.ErrFunc, error) {
bv, err := querytypes.BindVariablesToProto3(bindVars)
if err != nil {
return nil, nil, err
}
bindVars, err = querytypes.Proto3ToBindVariables(bv)
if err != nil {
return nil, nil, err
}
result := make(chan *sqltypes.Result, 10)
var finalErr error
go func() {
finalErr = itc.tablet.qsc.QueryService().StreamExecute(ctx, &querypb.Target{
Keyspace: itc.tablet.keyspace,
Shard: itc.tablet.shard,
TabletType: itc.tablet.tabletType,
}, query, bindVars, 0, func(reply *sqltypes.Result) error {
// We need to deep-copy the reply before returning,
// because the underlying buffers are reused.
result <- reply.Copy()
return nil
})
// the client will only access finalErr after the
// channel is closed, and then it's already set.
close(result)
}()
return result, func() error {
return tabletconn.TabletErrorFromGRPC(tabletserver.ToGRPCError(finalErr))
}, nil
}
示例2: SplitQuery
// SplitQuery is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) SplitQuery(ctx context.Context, request *vtgatepb.SplitQueryRequest) (response *vtgatepb.SplitQueryResponse, err error) {
defer vtg.server.HandlePanic(&err)
ctx = withCallerIDContext(ctx, request.CallerId)
bv, err := querytypes.Proto3ToBindVariables(request.Query.BindVariables)
if err != nil {
return nil, vterrors.ToGRPCError(err)
}
splits, vtgErr := vtgateservice.CallCorrectSplitQuery(
vtg.server,
request.UseSplitQueryV2,
ctx,
request.Keyspace,
string(request.Query.Sql),
bv,
request.SplitColumn,
request.SplitCount,
request.NumRowsPerQueryPart,
request.Algorithm)
if vtgErr != nil {
return nil, vterrors.ToGRPCError(vtgErr)
}
return &vtgatepb.SplitQueryResponse{
Splits: splits,
}, nil
}
示例3: BeginExecute
// BeginExecute is part of the queryservice.QueryServer interface
func (q *query) BeginExecute(ctx context.Context, request *querypb.BeginExecuteRequest) (response *querypb.BeginExecuteResponse, err error) {
defer q.server.HandlePanic(&err)
ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
request.EffectiveCallerId,
request.ImmediateCallerId,
)
bv, err := querytypes.Proto3ToBindVariables(request.Query.BindVariables)
if err != nil {
return nil, vterrors.ToGRPCError(err)
}
result, transactionID, err := q.server.BeginExecute(ctx, request.Target, request.Query.Sql, bv, request.Options)
if err != nil {
// if we have a valid transactionID, return the error in-band
if transactionID != 0 {
return &querypb.BeginExecuteResponse{
Error: vterrors.VtRPCErrorFromVtError(err),
TransactionId: transactionID,
}, nil
}
return nil, vterrors.ToGRPCError(err)
}
return &querypb.BeginExecuteResponse{
Result: sqltypes.ResultToProto3(result),
TransactionId: transactionID,
}, nil
}
示例4: StreamExecute
// StreamExecute is part of tabletconn.TabletConn
// We need to copy the bind variables as tablet server will change them.
func (itc *internalTabletConn) StreamExecute(ctx context.Context, target *querypb.Target, query string, bindVars map[string]interface{}, options *querypb.ExecuteOptions) (sqltypes.ResultStream, error) {
bv, err := querytypes.BindVariablesToProto3(bindVars)
if err != nil {
return nil, err
}
bindVars, err = querytypes.Proto3ToBindVariables(bv)
if err != nil {
return nil, err
}
result := make(chan *sqltypes.Result, 10)
var finalErr error
go func() {
finalErr = itc.tablet.qsc.QueryService().StreamExecute(ctx, target, query, bindVars, options, func(reply *sqltypes.Result) error {
// We need to deep-copy the reply before returning,
// because the underlying buffers are reused.
result <- reply.Copy()
return nil
})
finalErr = tabletconn.TabletErrorFromGRPC(vterrors.ToGRPCError(finalErr))
// the client will only access finalErr after the
// channel is closed, and then it's already set.
close(result)
}()
return &streamExecuteAdapter{result, &finalErr}, nil
}
示例5: Execute
// Execute is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) Execute(ctx context.Context, request *vtgatepb.ExecuteRequest) (response *vtgatepb.ExecuteResponse, err error) {
defer vtg.server.HandlePanic(&err)
ctx = withCallerIDContext(ctx, request.CallerId)
bv, err := querytypes.Proto3ToBindVariables(request.Query.BindVariables)
if err != nil {
return nil, vterrors.ToGRPCError(err)
}
result, err := vtg.server.Execute(ctx, string(request.Query.Sql), bv, request.Keyspace, request.TabletType, request.Session, request.NotInTransaction)
return &vtgatepb.ExecuteResponse{
Result: sqltypes.ResultToProto3(result),
Session: request.Session,
Error: vterrors.VtRPCErrorFromVtError(err),
}, nil
}
示例6: Execute
// Execute is part of tabletconn.TabletConn
// We need to copy the bind variables as tablet server will change them.
func (itc *internalTabletConn) Execute(ctx context.Context, target *querypb.Target, query string, bindVars map[string]interface{}, transactionID int64, options *querypb.ExecuteOptions) (*sqltypes.Result, error) {
bv, err := querytypes.BindVariablesToProto3(bindVars)
if err != nil {
return nil, err
}
bindVars, err = querytypes.Proto3ToBindVariables(bv)
if err != nil {
return nil, err
}
reply, err := itc.tablet.qsc.QueryService().Execute(ctx, target, query, bindVars, transactionID, options)
if err != nil {
return nil, tabletconn.TabletErrorFromGRPC(vterrors.ToGRPCError(err))
}
return reply, nil
}
示例7: ProtoToBoundShardQueries
// ProtoToBoundShardQueries transforms a list of BoundShardQuery from proto3
func ProtoToBoundShardQueries(bsq []*vtgatepb.BoundShardQuery) ([]BoundShardQuery, error) {
if len(bsq) == 0 {
return nil, nil
}
result := make([]BoundShardQuery, len(bsq))
for i, q := range bsq {
result[i].Sql = string(q.Query.Sql)
bv, err := querytypes.Proto3ToBindVariables(q.Query.BindVariables)
if err != nil {
return nil, err
}
result[i].BindVariables = bv
result[i].Keyspace = q.Keyspace
result[i].Shards = q.Shards
}
return result, nil
}
示例8: Execute
// Execute is part of the queryservice.QueryServer interface
func (q *query) Execute(ctx context.Context, request *querypb.ExecuteRequest) (response *querypb.ExecuteResponse, err error) {
defer q.server.HandlePanic(&err)
ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
request.EffectiveCallerId,
request.ImmediateCallerId,
)
bv, err := querytypes.Proto3ToBindVariables(request.Query.BindVariables)
if err != nil {
return nil, tabletserver.ToGRPCError(err)
}
result, err := q.server.Execute(ctx, request.Target, request.Query.Sql, bv, request.SessionId, request.TransactionId)
if err != nil {
return nil, tabletserver.ToGRPCError(err)
}
return &querypb.ExecuteResponse{
Result: sqltypes.ResultToProto3(result),
}, nil
}
示例9: Execute
// Execute is part of tabletconn.TabletConn
// We need to copy the bind variables as tablet server will change them.
func (itc *internalTabletConn) Execute(ctx context.Context, query string, bindVars map[string]interface{}, transactionID int64) (*sqltypes.Result, error) {
bv, err := querytypes.BindVariablesToProto3(bindVars)
if err != nil {
return nil, err
}
bindVars, err = querytypes.Proto3ToBindVariables(bv)
if err != nil {
return nil, err
}
reply, err := itc.tablet.qsc.QueryService().Execute(ctx, &querypb.Target{
Keyspace: itc.tablet.keyspace,
Shard: itc.tablet.shard,
TabletType: itc.tablet.tabletType,
}, query, bindVars, 0, transactionID)
if err != nil {
return nil, tabletconn.TabletErrorFromGRPC(tabletserver.ToGRPCError(err))
}
return reply, nil
}
示例10: StreamExecute
// StreamExecute is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) StreamExecute(request *vtgatepb.StreamExecuteRequest, stream vtgateservicepb.Vitess_StreamExecuteServer) (err error) {
defer vtg.server.HandlePanic(&err)
ctx := withCallerIDContext(stream.Context(), request.CallerId)
bv, err := querytypes.Proto3ToBindVariables(request.Query.BindVariables)
if err != nil {
return vterrors.ToGRPCError(err)
}
vtgErr := vtg.server.StreamExecute(ctx,
string(request.Query.Sql),
bv,
request.Keyspace,
request.TabletType,
func(value *sqltypes.Result) error {
return stream.Send(&vtgatepb.StreamExecuteResponse{
Result: sqltypes.ResultToProto3(value),
})
})
return vterrors.ToGRPCError(vtgErr)
}
示例11: StreamExecute
// StreamExecute is part of the queryservice.QueryServer interface
func (q *query) StreamExecute(request *querypb.StreamExecuteRequest, stream queryservicepb.Query_StreamExecuteServer) (err error) {
defer q.server.HandlePanic(&err)
ctx := callerid.NewContext(callinfo.GRPCCallInfo(stream.Context()),
request.EffectiveCallerId,
request.ImmediateCallerId,
)
bv, err := querytypes.Proto3ToBindVariables(request.Query.BindVariables)
if err != nil {
return tabletserver.ToGRPCError(err)
}
if err := q.server.StreamExecute(ctx, request.Target, request.Query.Sql, bv, request.SessionId, func(reply *sqltypes.Result) error {
return stream.Send(&querypb.StreamExecuteResponse{
Result: sqltypes.ResultToProto3(reply),
})
}); err != nil {
return tabletserver.ToGRPCError(err)
}
return nil
}
示例12: ExecuteBatch
// ExecuteBatch is part of tabletconn.TabletConn
// We need to copy the bind variables as tablet server will change them.
func (itc *internalTabletConn) ExecuteBatch(ctx context.Context, target *querypb.Target, queries []querytypes.BoundQuery, asTransaction bool, transactionID int64, options *querypb.ExecuteOptions) ([]sqltypes.Result, error) {
q := make([]querytypes.BoundQuery, len(queries))
for i, query := range queries {
bv, err := querytypes.BindVariablesToProto3(query.BindVariables)
if err != nil {
return nil, err
}
bindVars, err := querytypes.Proto3ToBindVariables(bv)
if err != nil {
return nil, err
}
q[i].Sql = query.Sql
q[i].BindVariables = bindVars
}
results, err := itc.tablet.qsc.QueryService().ExecuteBatch(ctx, target, q, asTransaction, transactionID, options)
if err != nil {
return nil, tabletconn.TabletErrorFromGRPC(vterrors.ToGRPCError(err))
}
return results, nil
}
示例13: StreamExecute
// StreamExecute is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) StreamExecute(request *vtgatepb.StreamExecuteRequest, stream vtgateservicepb.Vitess_StreamExecuteServer) (err error) {
defer vtg.server.HandlePanic(&err)
ctx := callerid.NewContext(callinfo.GRPCCallInfo(stream.Context()),
request.CallerId,
callerid.NewImmediateCallerID("grpc client"))
bv, err := querytypes.Proto3ToBindVariables(request.Query.BindVariables)
if err != nil {
return vterrors.ToGRPCError(err)
}
vtgErr := vtg.server.StreamExecute(ctx,
string(request.Query.Sql),
bv,
request.TabletType,
func(value *sqltypes.Result) error {
return stream.Send(&vtgatepb.StreamExecuteResponse{
Result: sqltypes.ResultToProto3(value),
})
})
return vterrors.ToGRPCError(vtgErr)
}
示例14: ExecuteKeyRanges
// ExecuteKeyRanges is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) ExecuteKeyRanges(ctx context.Context, request *vtgatepb.ExecuteKeyRangesRequest) (response *vtgatepb.ExecuteKeyRangesResponse, err error) {
defer vtg.server.HandlePanic(&err)
ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
request.CallerId,
callerid.NewImmediateCallerID("grpc client"))
bv, err := querytypes.Proto3ToBindVariables(request.Query.BindVariables)
if err != nil {
return nil, vterrors.ToGRPCError(err)
}
result, err := vtg.server.ExecuteKeyRanges(ctx,
string(request.Query.Sql),
bv,
request.Keyspace,
request.KeyRanges,
request.TabletType,
request.Session,
request.NotInTransaction)
return &vtgatepb.ExecuteKeyRangesResponse{
Result: sqltypes.ResultToProto3(result),
Session: request.Session,
Error: vterrors.VtRPCErrorFromVtError(err),
}, nil
}
示例15: SplitQuery
// SplitQuery is the RPC version of vtgateservice.VTGateService method
func (vtg *VTGate) SplitQuery(ctx context.Context, request *vtgatepb.SplitQueryRequest) (response *vtgatepb.SplitQueryResponse, err error) {
defer vtg.server.HandlePanic(&err)
ctx = callerid.NewContext(callinfo.GRPCCallInfo(ctx),
request.CallerId,
callerid.NewImmediateCallerID("grpc client"))
bv, err := querytypes.Proto3ToBindVariables(request.Query.BindVariables)
if err != nil {
return nil, vterrors.ToGRPCError(err)
}
splits, vtgErr := vtg.server.SplitQuery(ctx,
request.Keyspace,
string(request.Query.Sql),
bv,
request.SplitColumn,
request.SplitCount)
if vtgErr != nil {
return nil, vterrors.ToGRPCError(vtgErr)
}
return &vtgatepb.SplitQueryResponse{
Splits: splits,
}, nil
}