diff --git a/api_finished.go b/api_finished.go index 745d057..27d01f8 100644 --- a/api_finished.go +++ b/api_finished.go @@ -46,7 +46,7 @@ func (db *DB) UpsertVertex(in IVertex) error { func (db *DB) InsertEdge(in IEdge) error { vidSrcWithPolicy := GetVidWithPolicy(in.GetVidSrc(), in.GetVidSrcPolicy()) vidDstWithPolicy := GetVidWithPolicy(in.GetVidDst(), in.GetVidDstPolicy()) - sql, err := converts.ConvertToCreateEdgeSql(in, in.EdgeName(), vidSrcWithPolicy, vidDstWithPolicy) + sql, err := converts.ConvertToCreateEdgeSql(in, in.EdgeName(), vidSrcWithPolicy, vidDstWithPolicy, in.GetRank()) if err != nil { return err } diff --git a/internal/converts/insert_edge.go b/internal/converts/insert_edge.go index 400c9f3..9e42fbb 100644 --- a/internal/converts/insert_edge.go +++ b/internal/converts/insert_edge.go @@ -11,18 +11,19 @@ type createEdgeStruct struct { Name string Src, Dst string Keys, Values string + Rank int } var createEdgeTemplate = template.Must(template.New("insert_edge"). - Parse("insert edge {{.Name}}({{.Keys}}) values {{.Src}} -> {{.Dst}}:({{.Values}})")) + Parse("insert edge {{.Name}}({{.Keys}}) values {{.Src}} -> {{.Dst}}@{{.Rank}}:({{.Values}})")) // ConvertToCreateEdgeSql 转换结构体为创建边的 sql -func ConvertToCreateEdgeSql(in interface{}, edgeName string, src, dst string) (string, error) { +func ConvertToCreateEdgeSql(in interface{}, edgeName string, src, dst string, rank int) (string, error) { switch values := in.(type) { case map[string]interface{}: - return buildCreateEdgeSql(values, edgeName, src, dst), nil + return buildCreateEdgeSql(values, edgeName, src, dst, rank), nil case *map[string]interface{}: - return buildCreateEdgeSql(*values, edgeName, src, dst), nil + return buildCreateEdgeSql(*values, edgeName, src, dst, rank), nil case []map[string]interface{}: return "", errors.New("batch insert not support now") case *[]map[string]interface{}: @@ -32,11 +33,11 @@ func ConvertToCreateEdgeSql(in interface{}, edgeName string, src, dst string) (s if err != nil { return "", err } - return buildCreateEdgeSql(tagMap, edgeName, src, dst), nil + return buildCreateEdgeSql(tagMap, edgeName, src, dst, rank), nil } } -func buildCreateEdgeSql(tagMap map[string]interface{}, edgeName string, src, dst string) string { +func buildCreateEdgeSql(tagMap map[string]interface{}, edgeName string, src, dst string, rank int) string { keysStr, ValuesStr := genInsertKVs(tagMap) buf := new(strings.Builder) @@ -46,6 +47,7 @@ func buildCreateEdgeSql(tagMap map[string]interface{}, edgeName string, src, dst Dst: dst, Keys: keysStr, Values: ValuesStr, + Rank: rank, }) return buf.String() } diff --git a/model.go b/model.go index fb24855..0ec6a56 100644 --- a/model.go +++ b/model.go @@ -45,12 +45,14 @@ type ( GetVidSrcPolicy() constants.Policy GetVidDst() interface{} GetVidDstPolicy() constants.Policy + GetRank() int } EModel struct { Src interface{} `norm:"-"` SrcPolicy constants.Policy `norm:"-"` Dst interface{} `norm:"-"` DstPolicy constants.Policy `norm:"-"` + Rank int } ) @@ -76,6 +78,10 @@ func (v EModel) GetVidDstPolicy() constants.Policy { return v.DstPolicy } +func (v EModel) GetRank() int { + return v.Rank +} + func GetVidWithPolicy(vid interface{}, policy constants.Policy) string { vidStr := "" switch vid := vid.(type) {