예제 #1
0
func InsertOpenAccount(a *OpenAccount) error {
	_, err := gsql.Exec(_db, "insert into users("+openAccColumns+") values(?,?,?,?,?,?,?,?,?) "+
		"on duplicate key update access_token=?, refresh_token=?, expired_at=?, nick=?, avatar=?, updated_at=?, info=?",
		a.Type, a.OpenID, a.AccessToken, a.RefreshToken, a.ExpiredAt, time.Now().Unix(), a.Info,
		a.AccessToken, a.RefreshToken, a.ExpiredAt, a.Nick, a.Avatar, time.Now().Unix(), a.Info)
	return err
}
예제 #2
0
func UpsertIdentity(i *Identity) error {
	photos := json.MarshalStr(i.Photos)
	_, err := gsql.Exec(_db, `insert into identities(account_id, type, number, photos, created_at) values(?,?,?,?,?)
	on duplicate key update type=?, number=?, photos=?, created_at=?`, i.AccountID, i.Type, i.Number, photos,
		i.CreatedAt, i.Type, i.Number, photos, i.CreatedAt)
	return err
}
예제 #3
0
func InsertAccount(a *Account) error {
	if a.ID <= 0 {
		log.Panic("invalid id")
	}
	a.CreatedAt = time.Now().Unix()
	_, err := gsql.Exec(_db, "insert into accounts("+accountColumns+") values(?,?,?,?,?,?,?,?,?,?,?,?)",
		a.ID, a.OpenID, a.Mobile, a.Email, a.Password, a.LoginToken, a.Nick, a.Gender, a.Avatar,
		a.Birthdate, a.CreatedAt, a.Status)
	if err != nil {
		log.Error(err)
	}
	return err
}
예제 #4
0
파일: msg.go 프로젝트: justintan/dove
func (mr *MsgRepository) UpdateReadMsgID(userID types.ID, msgID types.ID) error {
	currentID, _ := mr.GetReadMsgID(userID)
	if currentID >= msgID {
		log.Warn("get old msgs", msgID, "current", currentID)
		return nil
	}
	_, err := gsql.Exec(mr.db, "insert into read_msgs(user_id, msg_id) values(?, ?) on duplicate key update msg_id=?", userID, msgID, msgID)
	if err != nil {
		return err
	}

	mr.urMu.Lock()
	mr.urIDs[userID] = msgID
	mr.urMu.Unlock()
	return nil
}
예제 #5
0
func UpdateAccount(a *Account) error {
	_, err := gsql.Exec(_db, "update accounts set mobile=?, email=?, password=?, login_token=?, nick=?, gender=?, avatar=?, birthdate=?, status=? where id=?",
		a.Mobile, a.Email, a.Password, a.LoginToken, a.Nick, a.Gender, a.Avatar, a.Birthdate, a.Status, a.ID)
	return err
}
예제 #6
0
파일: group.go 프로젝트: justintan/dove
func (gr *GroupRepository) SaveGroup(g *domain.GroupInfo) error {
	query := "insert into groups(id, owner_id, name, created_at) values(?,?,?,?)"
	_, err := gsql.Exec(gr.db, query, g.ID, g.OwnerID, g.Name, g.CreatedAt)
	return err
}
예제 #7
0
파일: group.go 프로젝트: justintan/dove
func (gr *GroupRepository) DelGroup(id types.ID) error {
	_, err := gsql.Exec(gr.db, "update groups set status=1 where id=?", id)
	return err
}
예제 #8
0
파일: group.go 프로젝트: justintan/dove
func (gr *GroupRepository) UpdateMember(groupID types.ID, m *domain.Member) error {
	_, err := gsql.Exec(gr.db, "update members set role=? and nick=? where group_id=? and user_id=?", m.Role, m.Nick, groupID, m.UserID)
	return err
}