本文整理汇总了Golang中github.com/coralproject/shelf/internal/platform/db.DB.NewCayley方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.NewCayley方法的具体用法?Golang DB.NewCayley怎么用?Golang DB.NewCayley使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coralproject/shelf/internal/platform/db.DB
的用法示例。
在下文中一共展示了DB.NewCayley方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: loadTestData
// loadTestData adds all the test data into the database.
func loadTestData(context interface{}, db *db.DB) error {
// Make sure the old data is clear.
if err := unloadTestData(context, db); err != nil {
if !graph.IsQuadNotExist(err) {
return err
}
}
// -----------------------------------------------------------
// Load example items, relationships, views, and patterns.
items, rels, vs, pats, err := wirefix.Get()
if err != nil {
return err
}
if err := wirefix.Add(context, db, items, rels, vs, pats); err != nil {
return err
}
// -----------------------------------------------------------
// Build the example graph.
mongoURI := cfg.MustURL("MONGO_URI")
if err := cayleyshelf.InitQuadStore(mongoURI.String()); err != nil {
return err
}
var quads []quad.Quad
quads = append(quads, quad.Make(wirePrefix+"d1dfa366-d2f7-4a4a-a64f-af89d4c97d82", wirePrefix+"on", wirePrefix+"c1b2bbfe-af9f-4903-8777-bd47c4d5b20a", ""))
quads = append(quads, quad.Make(wirePrefix+"6eaaa19f-da7a-4095-bbe3-cee7a7631dd4", wirePrefix+"on", wirePrefix+"c1b2bbfe-af9f-4903-8777-bd47c4d5b20a", ""))
quads = append(quads, quad.Make(wirePrefix+"d16790f8-13e9-4cb4-b9ef-d82835589660", wirePrefix+"on", wirePrefix+"c1b2bbfe-af9f-4903-8777-bd47c4d5b20a", ""))
quads = append(quads, quad.Make(wirePrefix+"80aa936a-f618-4234-a7be-df59a14cf8de", wirePrefix+"authored", wirePrefix+"d1dfa366-d2f7-4a4a-a64f-af89d4c97d82", ""))
quads = append(quads, quad.Make(wirePrefix+"80aa936a-f618-4234-a7be-df59a14cf8de", wirePrefix+"authored", wirePrefix+"6eaaa19f-da7a-4095-bbe3-cee7a7631dd4", ""))
quads = append(quads, quad.Make(wirePrefix+"a63af637-58af-472b-98c7-f5c00743bac6", wirePrefix+"authored", wirePrefix+"d16790f8-13e9-4cb4-b9ef-d82835589660", ""))
quads = append(quads, quad.Make(wirePrefix+"a63af637-58af-472b-98c7-f5c00743bac6", wirePrefix+"flagged", wirePrefix+"80aa936a-f618-4234-a7be-df59a14cf8de", ""))
tx := cayley.NewTransaction()
for _, quad := range quads {
tx.AddQuad(quad)
}
if err := db.NewCayley(tests.Context, tests.TestSession); err != nil {
return err
}
store, err := db.GraphHandle(tests.Context)
if err != nil {
return err
}
defer store.Close()
if err := store.ApplyTransaction(tx); err != nil {
return err
}
return nil
}
示例2: unloadTestData
// unloadTestData removes all the test data from the database.
func unloadTestData(context interface{}, db *db.DB) error {
// ------------------------------------------------------------
// Clear items, relationships, and views.
wirefix.Remove("context", db, wirePrefix)
// ------------------------------------------------------------
// Clear cayley graph.
var quads []quad.Quad
quads = append(quads, quad.Make(wirePrefix+"d1dfa366-d2f7-4a4a-a64f-af89d4c97d82", wirePrefix+"on", wirePrefix+"c1b2bbfe-af9f-4903-8777-bd47c4d5b20a", ""))
quads = append(quads, quad.Make(wirePrefix+"6eaaa19f-da7a-4095-bbe3-cee7a7631dd4", wirePrefix+"on", wirePrefix+"c1b2bbfe-af9f-4903-8777-bd47c4d5b20a", ""))
quads = append(quads, quad.Make(wirePrefix+"d16790f8-13e9-4cb4-b9ef-d82835589660", wirePrefix+"on", wirePrefix+"c1b2bbfe-af9f-4903-8777-bd47c4d5b20a", ""))
quads = append(quads, quad.Make(wirePrefix+"80aa936a-f618-4234-a7be-df59a14cf8de", wirePrefix+"authored", wirePrefix+"d1dfa366-d2f7-4a4a-a64f-af89d4c97d82", ""))
quads = append(quads, quad.Make(wirePrefix+"80aa936a-f618-4234-a7be-df59a14cf8de", wirePrefix+"authored", wirePrefix+"6eaaa19f-da7a-4095-bbe3-cee7a7631dd4", ""))
quads = append(quads, quad.Make(wirePrefix+"a63af637-58af-472b-98c7-f5c00743bac6", wirePrefix+"authored", wirePrefix+"d16790f8-13e9-4cb4-b9ef-d82835589660", ""))
quads = append(quads, quad.Make(wirePrefix+"a63af637-58af-472b-98c7-f5c00743bac6", wirePrefix+"flagged", wirePrefix+"80aa936a-f618-4234-a7be-df59a14cf8de", ""))
tx := cayley.NewTransaction()
for _, quad := range quads {
tx.RemoveQuad(quad)
}
if err := db.NewCayley(tests.Context, tests.TestSession); err != nil {
return err
}
store, err := db.GraphHandle(tests.Context)
if err != nil {
return err
}
defer store.Close()
if err := store.ApplyTransaction(tx); err != nil {
return err
}
return nil
}
示例3: main
func main() {
// Initialize the configuration
if err := cfg.Init(cfg.EnvProvider{Namespace: "WIRE"}); err != nil {
wire.Println("Unable to initialize configuration")
os.Exit(1)
}
// Initialize the logging
logLevel := func() int {
ll, err := cfg.Int(cfgLoggingLevel)
if err != nil {
return log.NONE
}
return ll
}
log.Init(os.Stderr, logLevel, log.Ldefault)
wire.Println("Using log level", logLevel())
// Pull options from the config.
var mgoDB *db.DB
var graphDB *cayley.Handle
// Configure MongoDB.
wire.Println("Configuring MongoDB")
mongoURI := cfg.MustURL(cfgMongoURI)
err := db.RegMasterSession("startup", mongoURI.Path, mongoURI.String(), 0)
if err != nil {
wire.Println("Unable to initialize MongoDB")
os.Exit(1)
}
mgoDB, err = db.NewMGO("startup", mongoURI.Path)
if err != nil {
wire.Println("Unable to get MongoDB session")
os.Exit(1)
}
defer mgoDB.CloseMGO("")
// Configure Cayley.
wire.Println("Configuring Cayley")
if err := mgoDB.NewCayley("startup", mongoURI.Path); err != nil {
wire.Println("Unable to get Cayley support")
}
graphDB, err = mgoDB.GraphHandle("startup")
if err != nil {
wire.Println("Unable to get Cayley handle")
os.Exit(1)
}
// Add the graph and view commands to the CLI tool.
wire.AddCommand(
cmdview.GetCommands(mgoDB, graphDB),
)
// Execute the command.
wire.Execute()
}