示例#1
0
func (g *Graph) WriteBatch(triples []Triple, opts *rocks.WriteOptions) error {
	if opts == nil {
		opts = g.wopts
	}
	batch := rocks.NewWriteBatch()
	for _, triple := range triples {
		batch.Put(triple.Key(), triple.Val())
	}
	err := g.db.Write(opts, batch)
	if err == nil {
		g.IncWrites(uint64(len(triples)))
	}
	return err
}
示例#2
0
func (g *Graph) WriteIndexedTriples(triples []*Triple, opts *rocks.WriteOptions) error {
	if opts == nil {
		opts = g.wopts
	}
	batch := rocks.NewWriteBatch()
	for _, triple := range triples {
		v := triple.Val()
		// ToDo: Optimize
		batch.Put(withIndex(SPO, triple.Copy().Permute(SPO).Key()), v)
		batch.Put(withIndex(OPS, triple.Copy().Permute(OPS).Key()), v)
		batch.Put(withIndex(PSO, triple.Copy().Permute(PSO).Key()), v)
	}
	err := g.db.Write(opts, batch)
	if err == nil {
		g.IncWrites(uint64(3 * len(triples)))
	}
	return err
}
示例#3
0
func (g *Graph) WriteIndexedTriple(triple *Triple, opts *rocks.WriteOptions) error {
	if opts == nil {
		opts = g.wopts
	}
	if opts == nil {
		panic(fmt.Errorf("nil wopts"))
	}
	batch := rocks.NewWriteBatch()
	v := triple.Val()
	// ToDo: Optimize
	batch.Put(withIndex(SPO, triple.Copy().Permute(SPO).Key()), v)
	batch.Put(withIndex(OPS, triple.Copy().Permute(OPS).Key()), v)
	batch.Put(withIndex(PSO, triple.Copy().Permute(PSO).Key()), v)
	err := g.db.Write(opts, batch)
	if err == nil {
		g.IncWrites(uint64(3))
	}
	return err
}