示例#1
0
文件: query.go 项目: rach/pome
func connectDB(host string, dbname string, username string, password string, sslmode string, port int) *sqlx.DB {
	// TODO This could be rewritten in a nicer way
	dbURL := connectionString(host, dbname, username, password, sslmode, port)
	db := sqlx.MustOpen("postgres", dbURL)
	// we do a manual ping because MustConnect raise a panic
	err := db.Ping()
	if err != nil {
		if len(password) > 0 || !strings.Contains(err.Error(), "password authentication failed") {
			log.Fatal(err)
		}
		pwd := ""
		fmt.Print("Enter Password: "******"postgres", dbURL)
		err := db.Ping()
		if err != nil {
			log.Fatal(err)
		}
	}
	return db
}
示例#2
0
文件: query.go 项目: ferfebles/pome
func connectDB(dbURL string) *sqlx.DB {
	db := sqlx.MustOpen("postgres", dbURL)
	return db
}