From 3347c43055556f7c81ba862eb1c693f22fc74d10 Mon Sep 17 00:00:00 2001 From: Nicolas Duhamel Date: Fri, 5 Feb 2016 21:32:06 +0100 Subject: [PATCH] First commit --- run.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 run.go diff --git a/run.go b/run.go new file mode 100644 index 0000000..303fba7 --- /dev/null +++ b/run.go @@ -0,0 +1,35 @@ +package main + +import ( + "flag" + + "github.com/jmoiron/sqlx" + "github.com/kr/pretty" + _ "github.com/lib/pq" +) + +var pg string +var sqlFile string + +func init() { + flag.StringVar(&pg, "pg", "", "postgres database's connection string") + flag.StringVar(&sqlFile, "file", "", "path to a sql file") +} + +func main() { + flag.Parse() + + db := sqlx.MustConnect("postgres", pg) + err := db.Ping() + if err != nil { + pretty.Println(err) + } + + if sqlFile != "" { + r, err := sqlx.LoadFile(db, sqlFile) + if err != nil { + pretty.Println(err) + } + pretty.Println(r) + } +}