internal dump routine

This commit is contained in:
David Schor 2015-08-10 01:58:25 -04:00
parent 85a1bbdf0e
commit 00b13d2ac1
2 changed files with 41 additions and 1 deletions

36
internal/dump.go Normal file
View file

@ -0,0 +1,36 @@
package internal
import (
"fmt"
"os"
"github.com/google/cayley/graph"
"github.com/google/cayley/exporter"
)
// Dump the content of the database into a file based
// on a few different formats
func Dump(qs graph.QuadStore, outFile, typ string) error {
var f *os.File
if outFile == "-" {
f = os.Stdout
} else {
var err error
f, err = os.Create(outFile)
if err != nil {
return fmt.Errorf("could not open file %q: %v", outFile, err)
}
defer f.Close()
fmt.Printf("dumping db to file %q\n", outFile)
}
export := exporter.NewExporter(f, qs)
if export.Err() != nil {
return export.Err()
}
if outFile != "-" {
fmt.Printf("%d entries were written\n", export.Count())
}
return nil
}