Skip to content

Commit

Permalink
feat: add aql statements for inserting and updating the terms
Browse files Browse the repository at this point in the history
  • Loading branch information
cybersiddhu committed Oct 4, 2018
1 parent b0c8941 commit 5ef72dd
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions storage/arangodb/statement.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package arangodb

import "fmt"

const (
tinst = `
LET fcv = (
FOR cv IN %s
FILTER cv.id == "%s"
RETURN cv._id
)
LET existing = (
FOR cvt IN %s
FILTER fcv[0] == cvt.graph_id
RETURN cvt.id
)
LET latest = (
FOR cvt IN %s
FILTER fcv[0] == cvt.graph_id
RETURN cvt.id
)
FOR diff IN MINUS(latest,existing)
FOR cvt IN %s
FILTER diff == cvt.id
INSERT UNSET(cvt,["_key","_id","_rev"]) IN %s
COLLECT WITH COUNT INTO c
RETURN c
`
tupdt = `
LET fcv = (
FOR cv in %s
FILTER cv.id == "%s"
RETURN cv._id
)
LET existing = (
FOR cvt in %s
FILTER fcv[0] == cvt.graph_id
RETURN cvt.id
)
LET latest = (
FOR cvt in %s
FILTER fcv[0] == cvt.graph_id
RETURN cvt.id
)
FOR ins in INTERSECTION(latest,existing)
FOR lcvt in %s
FOR ecvt in %s
FILTER ins == lcvt.id
FILTER ins == ecvt.id
UPDATE {
_key: ecvt._key,
label: lcvt.label,
metadata: lcvt.metadata
} IN %s
COLLECT WITH COUNT INTO c
RETURN c
`
)

func termInsert(n, g, t, temp string) string {
return fmt.Sprintf(
tinst,
g, n, t, temp, temp, t,
)
}

func termUpdate(n, g, t, temp string) string {
return fmt.Sprintf(
tupdt,
g, n, t, temp, temp, t, t,
)
}

0 comments on commit 5ef72dd

Please sign in to comment.