-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add aql statements for inserting and updating the terms
- Loading branch information
1 parent
b0c8941
commit 5ef72dd
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} |