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")) } }
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 }
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 }
func UpdateRelationship(rship *Relationship) error { db := pg.Connect(conf.GetDbConf()) defer db.Close() err := db.Update(rship) return err }
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 }