Example #1
0
func InitDatabase(w http.ResponseWriter, r *http.Request) {
	db := pg.Connect(conf.GetDbConf())
	err := createSchema(db)
	if err != nil {
		w.Write([]byte(err.Error()))
	} else {
		w.Write([]byte("Datatable create ok!\n"))
	}
}
Example #2
0
func GetRshipById(id string) ([]Relationship, error) {
	db := pg.Connect(conf.GetDbConf())
	defer db.Close()

	var rships []Relationship
	//err := db.Model(&rships).Select(rship)
	err := db.Model(&rships).Where("id = ?", id).Order("user_id").Select()
	return rships, err
}
Example #3
0
func GetRshipByRid(id, oid string) (*Relationship, error) {
	db := pg.Connect(conf.GetDbConf())
	defer db.Close()
	// Select all users.
	rship := &Relationship{
		Id:      id,
		User_id: oid,
	}
	err := db.Select(rship)
	return rship, err
}
Example #4
0
func UpdateRelationship(rship *Relationship) error {
	db := pg.Connect(conf.GetDbConf())
	defer db.Close()
	err := db.Update(rship)
	return err
}
Example #5
0
func CreateOrUpdteRelationship(rship *Relationship) error {
	db := pg.Connect(conf.GetDbConf())
	defer db.Close()
	_, err := db.Model(&rship).OnConflict("(id, user_id) DO UPDATE").Set("state = ?state").Create()
	return err
}