-
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.
- Loading branch information
1 parent
1056b1a
commit 9b730df
Showing
3 changed files
with
107 additions
and
2 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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
module github.com/dictyBase/go-obograph | ||
|
||
require ( | ||
github.com/arangodb/go-driver v0.0.0-20210304082257-d7e0ea043b7f | ||
github.com/arangodb/go-driver v0.0.0-20210804111724-721038b2c5bd | ||
github.com/dictyBase/arangomanager v0.3.1 | ||
github.com/go-playground/validator/v10 v10.8.0 | ||
github.com/go-playground/validator/v10 v10.9.0 | ||
github.com/sirupsen/logrus v1.8.1 | ||
github.com/urfave/cli v1.22.5 | ||
golang.org/x/crypto v0.0.0-20210812204632-0ba0e8f03122 // indirect | ||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e // indirect | ||
golang.org/x/text v0.3.7 // indirect | ||
) | ||
|
||
go 1.16 |
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
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 ( | ||
"context" | ||
|
||
driver "github.com/arangodb/go-driver" | ||
manager "github.com/dictyBase/arangomanager" | ||
) | ||
|
||
type OntoCollection struct { | ||
Term driver.Collection | ||
Rel driver.Collection | ||
Cv driver.Collection | ||
Obog driver.Graph | ||
} | ||
|
||
// CreateCollection creates all the necessary collections, graph and index required | ||
// for persisting obojson ontology in arangodb | ||
func CreateCollection(db *manager.Database, collP *CollectionParams) (*OntoCollection, error) { | ||
oc, err := docCollection(db, collP) | ||
if err != nil { | ||
return oc, err | ||
} | ||
obog, err := db.FindOrCreateGraph( | ||
collP.OboGraph, | ||
[]driver.EdgeDefinition{{ | ||
Collection: oc.Rel.Name(), | ||
From: []string{oc.Term.Name()}, | ||
To: []string{oc.Term.Name()}, | ||
}}) | ||
if err != nil { | ||
return oc, err | ||
} | ||
oc.Obog = obog | ||
_, _, err = oc.Term.EnsurePersistentIndex( | ||
context.Background(), | ||
[]string{"label"}, | ||
&driver.EnsurePersistentIndexOptions{ | ||
Name: "label-idx", | ||
InBackground: true, | ||
}) | ||
return oc, err | ||
} | ||
|
||
func docCollection(db *manager.Database, collP *CollectionParams) (*OntoCollection, error) { | ||
oc := &OntoCollection{} | ||
termc, err := db.FindOrCreateCollection( | ||
collP.Term, | ||
&driver.CreateCollectionOptions{}, | ||
) | ||
if err != nil { | ||
return oc, err | ||
} | ||
relc, err := db.FindOrCreateCollection( | ||
collP.Relationship, | ||
&driver.CreateCollectionOptions{Type: driver.CollectionTypeEdge}, | ||
) | ||
if err != nil { | ||
return oc, err | ||
} | ||
graphc, err := db.FindOrCreateCollection( | ||
collP.GraphInfo, | ||
&driver.CreateCollectionOptions{}, | ||
) | ||
if err != nil { | ||
return oc, err | ||
} | ||
oc.Term = termc | ||
oc.Rel = relc | ||
oc.Cv = graphc | ||
return oc, nil | ||
} |