func newQuadStore(addr string, options graph.Options) (graph.QuadStore, error) { var qs QuadStore conn, err := mgo.Dial(addr) if err != nil { return nil, err } conn.SetSafe(&mgo.Safe{}) dbName := DefaultDBName val, ok, err := options.StringKey("database_name") if err != nil { return nil, err } else if ok { dbName = val } qs.db = conn.DB(dbName) qs.session = conn qs.ids = newCache(1 << 16) qs.sizes = newCache(1 << 16) return &qs, nil }
func createNewMongoGraph(addr string, options graph.Options) error { conn, err := mgo.Dial(addr) if err != nil { return err } conn.SetSafe(&mgo.Safe{}) dbName := DefaultDBName val, ok, err := options.StringKey("database_name") if err != nil { return err } else if ok { dbName = val } db := conn.DB(dbName) indexOpts := mgo.Index{ Key: []string{"subject"}, Unique: false, DropDups: false, Background: true, Sparse: true, } db.C("quads").EnsureIndex(indexOpts) indexOpts.Key = []string{"predicate"} db.C("quads").EnsureIndex(indexOpts) indexOpts.Key = []string{"object"} db.C("quads").EnsureIndex(indexOpts) indexOpts.Key = []string{"label"} db.C("quads").EnsureIndex(indexOpts) logOpts := mgo.Index{ Key: []string{"LogID"}, Unique: true, DropDups: false, Background: true, Sparse: true, } db.C("log").EnsureIndex(logOpts) return nil }