First commit
This commit is contained in:
commit
3347c43055
35
run.go
Normal file
35
run.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user