Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rank support when insert edge #16

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api_finished.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 8 additions & 6 deletions internal/converts/insert_edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}:
Expand All @@ -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)
Expand All @@ -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()
}
6 changes: 6 additions & 0 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)

Expand All @@ -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) {
Expand Down