First commit

This commit is contained in:
Nicolas Duhamel 2016-02-05 21:32:06 +01:00
commit 3347c43055

35
run.go Normal file
View File

@ -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)
}
}