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