internal dump routine
This commit is contained in:
parent
85a1bbdf0e
commit
00b13d2ac1
2 changed files with 41 additions and 1 deletions
|
|
@ -219,7 +219,11 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal.Dump()
|
err = internal.Dump(handle.QuadStore, *dumpFile, *dumpType)
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
handle.Close()
|
handle.Close()
|
||||||
|
|
||||||
case "repl":
|
case "repl":
|
||||||
|
|
|
||||||
36
internal/dump.go
Normal file
36
internal/dump.go
Normal 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
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue