Esempio n. 1
0
func initDb() (*graph.NodeGraph, error) {
	var handle *cayley.Handle
	var err error
	if !debug {
		dbPath := filepath.Join(env.EnvPath(env.DbPath), "db.dat")
		if !env.Exists(dbPath) {
			if err = cgraph.InitQuadStore("bolt", dbPath, nil); err != nil {
				return nil, err
			}
		}
		if handle, err = cayley.NewGraph("bolt", dbPath, nil); err != nil {
			return nil, err
		}
	} else {
		if handle, err = cayley.NewMemoryGraph(); err != nil {
			return nil, err
		}
	}

	return graph.NewGraph(handle)
}
Esempio n. 2
0
func TestInit() (*graph.NodeGraph, string) {
	if dir, err := ioutil.TempDir(os.TempDir(), ".olympus"); err != nil {
		panic(err)
	} else {
		os.Setenv("OLYMPUS_HOME", dir)
		if err = env.InitializeEnvironment(); err != nil {
			panic(err)
		}

		dbPath := filepath.Join(env.EnvPath(env.DbPath), "db.dat")
		if !env.Exists(dbPath) {
			cgraph.InitQuadStore("bolt", dbPath, nil)
			if handle, err := cayley.NewGraph("bolt", dbPath, nil); err != nil {
				panic(err)
			} else if ng, err := graph.NewGraph(handle); err != nil {
				panic(err)
			} else {
				return ng, dir
			}
		} else {
			return nil, ""
		}
	}
}