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


Golang sqlannotation.AddKeyspaceID函数代码示例

本文整理汇总了Golang中github.com/youtube/vitess/go/vt/sqlannotation.AddKeyspaceID函数的典型用法代码示例。如果您正苦于以下问题:Golang AddKeyspaceID函数的具体用法?Golang AddKeyspaceID怎么用?Golang AddKeyspaceID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: execDeleteEqual

func (rtr *Router) execDeleteEqual(vcursor *requestContext, plan *planbuilder.Plan) (*mproto.QueryResult, error) {
	keys, err := rtr.resolveKeys([]interface{}{plan.Values}, vcursor.bindVariables)
	if err != nil {
		return nil, fmt.Errorf("execDeleteEqual: %v", err)
	}
	ks, shard, ksid, err := rtr.resolveSingleShard(vcursor, keys[0], plan)
	if err != nil {
		return nil, fmt.Errorf("execDeleteEqual: %v", err)
	}
	if len(ksid) == 0 {
		return &mproto.QueryResult{}, nil
	}
	if plan.Subquery != "" {
		err = rtr.deleteVindexEntries(vcursor, plan, ks, shard, ksid)
		if err != nil {
			return nil, fmt.Errorf("execDeleteEqual: %v", err)
		}
	}
	vcursor.bindVariables[ksidName] = string(ksid)
	rewritten := sqlannotation.AddKeyspaceID(plan.Rewritten, ksid)
	return rtr.scatterConn.Execute(
		vcursor.ctx,
		rewritten,
		vcursor.bindVariables,
		ks,
		[]string{shard},
		vcursor.tabletType,
		NewSafeSession(vcursor.session),
		vcursor.notInTransaction)
}
开发者ID:richarwu,项目名称:vitess,代码行数:30,代码来源:router.go

示例2: execDeleteEqual

func (rtr *Router) execDeleteEqual(vcursor *requestContext, route *engine.Route) (*sqltypes.Result, error) {
	keys, err := rtr.resolveKeys([]interface{}{route.Values}, vcursor.bindVars)
	if err != nil {
		return nil, fmt.Errorf("execDeleteEqual: %v", err)
	}
	ks, shard, ksid, err := rtr.resolveSingleShard(vcursor, keys[0], route)
	if err != nil {
		return nil, fmt.Errorf("execDeleteEqual: %v", err)
	}
	if len(ksid) == 0 {
		return &sqltypes.Result{}, nil
	}
	if route.Subquery != "" {
		err = rtr.deleteVindexEntries(vcursor, route, ks, shard, ksid)
		if err != nil {
			return nil, fmt.Errorf("execDeleteEqual: %v", err)
		}
	}
	rewritten := sqlannotation.AddKeyspaceID(route.Query, ksid, vcursor.comments)
	return rtr.scatterConn.Execute(
		vcursor.ctx,
		rewritten,
		vcursor.bindVars,
		ks,
		[]string{shard},
		vcursor.tabletType,
		NewSafeSession(vcursor.session),
		vcursor.notInTransaction)
}
开发者ID:jmptrader,项目名称:vitess,代码行数:29,代码来源:router.go

示例3: execInsertSharded

func (rtr *Router) execInsertSharded(vcursor *requestContext, route *engine.Route) (*sqltypes.Result, error) {
	var firstKsid []byte
	var firstAutoGenInsertID int64
	inputs := route.Values.([]interface{})
	for rowNum, input := range inputs {
		insertid, err := rtr.handleGenerate(vcursor, route.Generate, rowNum)
		if firstAutoGenInsertID == 0 && insertid != 0 {
			firstAutoGenInsertID = insertid
		}
		if err != nil {
			return nil, fmt.Errorf("execInsertSharded: %v", err)
		}

		keys, err := rtr.resolveKeys(input.([]interface{}), vcursor.bindVars)
		if err != nil {
			return nil, fmt.Errorf("execInsertSharded: %v", err)
		}
		for colNum := 0; colNum < len(keys); colNum++ {
			if rowNum == 0 && colNum == 0 {
				ksid, err := rtr.handlePrimary(vcursor, keys[0], route.Table.ColumnVindexes[0], vcursor.bindVars, rowNum)
				if err != nil {
					return nil, fmt.Errorf("execInsertSharded: %v", err)
				}
				firstKsid = ksid
			} else {
				err := rtr.handleNonPrimary(vcursor, keys[colNum], route.Table.ColumnVindexes[colNum], vcursor.bindVars, firstKsid, rowNum)
				if err != nil {
					return nil, fmt.Errorf("execInsertSharded: %v", err)
				}
			}
		}
	}

	ks, shard, err := rtr.getRouting(vcursor.ctx, route.Keyspace.Name, vcursor.tabletType, firstKsid)
	if err != nil {
		return nil, fmt.Errorf("execInsertSharded: %v", err)
	}

	rewritten := sqlannotation.AddKeyspaceID(route.Query, firstKsid, vcursor.comments)
	result, err := rtr.scatterConn.Execute(
		vcursor.ctx,
		rewritten,
		vcursor.bindVars,
		ks,
		[]string{shard},
		vcursor.tabletType,
		NewSafeSession(vcursor.session),
		vcursor.notInTransaction)

	if err != nil {
		return nil, fmt.Errorf("execInsertSharded: %v", err)
	}
	if firstAutoGenInsertID != 0 {
		if result.InsertID != 0 {
			return nil, fmt.Errorf("sequence and db generated a value each for insert")
		}
		result.InsertID = uint64(firstAutoGenInsertID)
	}
	return result, nil
}
开发者ID:jmptrader,项目名称:vitess,代码行数:60,代码来源:router.go

示例4: execInsertSharded

func (rtr *Router) execInsertSharded(vcursor *requestContext, plan *planbuilder.Plan) (*mproto.QueryResult, error) {
	input := plan.Values.([]interface{})
	keys, err := rtr.resolveKeys(input, vcursor.bindVariables)
	if err != nil {
		return nil, fmt.Errorf("execInsertSharded: %v", err)
	}
	ksid, generated, err := rtr.handlePrimary(vcursor, keys[0], plan.Table.ColVindexes[0], vcursor.bindVariables)
	if err != nil {
		return nil, fmt.Errorf("execInsertSharded: %v", err)
	}
	ks, shard, err := rtr.getRouting(vcursor.ctx, plan.Table.Keyspace.Name, vcursor.tabletType, ksid)
	if err != nil {
		return nil, fmt.Errorf("execInsertSharded: %v", err)
	}
	for i := 1; i < len(keys); i++ {
		newgen, err := rtr.handleNonPrimary(vcursor, keys[i], plan.Table.ColVindexes[i], vcursor.bindVariables, ksid)
		if err != nil {
			return nil, err
		}
		if newgen != 0 {
			if generated != 0 {
				return nil, fmt.Errorf("insert generated more than one value")
			}
			generated = newgen
		}
	}
	vcursor.bindVariables[ksidName] = string(ksid)
	rewritten := sqlannotation.AddKeyspaceID(plan.Rewritten, ksid)
	result, err := rtr.scatterConn.Execute(
		vcursor.ctx,
		rewritten,
		vcursor.bindVariables,
		ks,
		[]string{shard},
		vcursor.tabletType,
		NewSafeSession(vcursor.session),
		vcursor.notInTransaction)
	if err != nil {
		return nil, fmt.Errorf("execInsertSharded: %v", err)
	}
	if generated != 0 {
		if result.InsertId != 0 {
			return nil, fmt.Errorf("vindex and db generated a value each for insert")
		}
		result.InsertId = uint64(generated)
	}
	return result, nil
}
开发者ID:richarwu,项目名称:vitess,代码行数:48,代码来源:router.go

示例5: execInsertSharded

func (rtr *Router) execInsertSharded(vcursor *requestContext, route *engine.Route) (*sqltypes.Result, error) {
	insertid, err := rtr.handleGenerate(vcursor, route.Generate)
	if err != nil {
		return nil, fmt.Errorf("execInsertSharded: %v", err)
	}
	input := route.Values.([]interface{})
	keys, err := rtr.resolveKeys(input, vcursor.bindVars)
	if err != nil {
		return nil, fmt.Errorf("execInsertSharded: %v", err)
	}
	ksid, err := rtr.handlePrimary(vcursor, keys[0], route.Table.ColVindexes[0], vcursor.bindVars)
	if err != nil {
		return nil, fmt.Errorf("execInsertSharded: %v", err)
	}
	ks, shard, err := rtr.getRouting(vcursor.ctx, route.Keyspace.Name, vcursor.tabletType, ksid)
	if err != nil {
		return nil, fmt.Errorf("execInsertSharded: %v", err)
	}
	for i := 1; i < len(keys); i++ {
		err := rtr.handleNonPrimary(vcursor, keys[i], route.Table.ColVindexes[i], vcursor.bindVars, ksid)
		if err != nil {
			return nil, err
		}
	}
	vcursor.bindVars[ksidName] = string(ksid)
	rewritten := sqlannotation.AddKeyspaceID(route.Query, ksid)
	result, err := rtr.scatterConn.Execute(
		vcursor.ctx,
		rewritten,
		vcursor.bindVars,
		ks,
		[]string{shard},
		vcursor.tabletType,
		NewSafeSession(vcursor.session),
		vcursor.notInTransaction)
	if err != nil {
		return nil, fmt.Errorf("execInsertSharded: %v", err)
	}
	if insertid != 0 {
		if result.InsertID != 0 {
			return nil, fmt.Errorf("sequence and db generated a value each for insert")
		}
		result.InsertID = uint64(insertid)
	}
	return result, nil
}
开发者ID:aaijazi,项目名称:vitess,代码行数:46,代码来源:router.go


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