예제 #1
0
func TestMysqlToMongo(t *testing.T) {
	UserInfoInit()
	sqlStr := "select uid, phonenum, password, platform, did, setupid,baseinfo, exinfo from t_user_info"
	row, err := common.MysqlQuery(sqlStr)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer row.Close()
	userInfo := &UserInfo{}
	for row.Next() {
		if err := row.Scan(&userInfo.Uid,
			&userInfo.PhoneNum,
			&userInfo.Password,
			&userInfo.Platform,
			&userInfo.DeviceId,
			&userInfo.SetupId,
			&userInfo.BaseInfo,
			&userInfo.ExInfo); err != nil {
			fmt.Println(err)
		}

		if err := SaveUserInfo(userInfo); err != nil {
			fmt.Println(err)
		}
	}
}
예제 #2
0
파일: token.go 프로젝트: sunyuantao/windows
func DBGetUidByToken(token string) (uint64, error) {
	var uid uint64 = 0
	sqlStr := fmt.Sprintf("select uid from t_devicetoken where token = '%d'", token)

	rows, err := common.MysqlQuery(sqlStr)
	if err != nil {
		return 0, errors.As(err)
	}
	defer rows.Close()

	for rows.Next() {
		if err := rows.Scan(&uid); err != nil {
			return uid, errors.As(err, token)
		}
	}

	return uid, nil
}