func createDbrConn() *dbr.Connection {
	conn, err := dbr.Open("postgres", "user=pgtest dbname=pgtest sslmode=disable", nil)
	if err != nil {
		log.Fatalf("failed to open: %s", err)
	}
	return conn
}
Esempio n. 2
0
func getSession() *dbr.Session {

	db, err := dbr.Open("mysql",
		conf.USER+":"+conf.PASSWORD+"@tcp("+conf.HOST+":"+conf.PORT+")/"+conf.DB,
		nil)

	if err != nil {
		logrus.Error(err)
	} else {
		session := db.NewSession(nil)
		return session
	}
	return nil
}
func DbrRead(id int) {

	connString := "host=192.168.200.10 user=postgres password=postgres dbname=test sslmode=disable"

	conn, _ := dbr.Open("postgres", connString, nil)
	db := conn.NewSession(nil)
	defer db.Close()

	//var user []User
	//if _, err := db.Select("*").From("user").Load(&user); err != nil {
	//if _, err := db.Select("*").From("user").Where("Id = ?", id).Load(&user); err != nil {
	//var user User
	//if _, err := db.Select("*").From("user").Where("id = ?", id).Load(&user); err != nil {
	//	panic(err)
	//}

	var user User
	db.Select("*").From("user").Where("id = ?", 1).LoadStruct(&user)
}