Created
September 2, 2015 00:06
-
-
Save nad2000/7f7d887b85edfdbcdeb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"os" | |
"gopkg.in/pg.v3" | |
) | |
func copyTo(fileName string) { | |
//db := pg.Connect(&pg.Options{ User: "postgres", }) | |
pgHost := os.Getenv("PGHOST") | |
if pgHost == "local" { | |
pgHost = "/tmp/.s.PGSQL.5432" | |
} | |
opt := pg.Options{ | |
Host: pgHost, | |
User: os.Getenv("PGUSER"), | |
Database: os.Getenv("PGDATABASE"), | |
} | |
fmt.Printf("%t\n", opt) | |
db := pg.Connect(&opt) | |
fo, err := os.Create(fileName) | |
if err != nil { | |
fmt.Println(err.Error()) | |
panic(err) | |
} | |
_, err = db.CopyTo(fo, "COPY tcp_samples TO STDOUT") | |
if err != nil { | |
fmt.Println(err.Error()) | |
panic(err) | |
} | |
fo.Close() | |
} | |
func main() { | |
var dumpFileName string | |
flag.StringVar(&dumpFileName, "o", "/tmp/output.copy", "COPY TO file nane") | |
flag.Parse() | |
//ExampleDB_Query() | |
copyTo(dumpFileName) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment