TeamTalk db_proxy_server CRelationModel详解

1. 简介

用于db_proxy_server操作mysql IMRelationShip表成员关系信息(增删改)

2. 类与接口

① uint32_t getRelationId(uint32_t nUserAId, uint32_t nUserBId, bool bAdd)
从mysql IMRelationShip表获取nUserAId和nUserBId的关系信息
bAdd为true时,若未查到则添加
返回查询到的记录id

② uint32_t addRelation(uint32_t nSmallId, uint32_t nBigId)
向mysql IMRelationShip表添加nSmallId和nBigId关系信息,有则更新,没有则添加
返回该条记录的id

③ bool updateRelation(uint32_t nRelationId, uint32_t nUpdateTime)
修改mysql IMRelationShip表指定id为nRelationId的更新时间为nUpdateTime
返回执行结果,true成功,false失败

④ bool removeRelation(uint32_t nRelationId)
删除mysql IMRelationShip表指定id为nRelationId的关系信息
实际上未删除记录,只更新了status为删除状态
返回执行结果,true成功,false失败

3. IMRelationShip
CREATE TABLE `IMRelationShip` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `smallId` int(11) unsigned NOT NULL COMMENT '用户A的id',
  `bigId` int(11) unsigned NOT NULL COMMENT '用户B的id',
  `status` tinyint(1) unsigned DEFAULT '0' COMMENT '用户:0-正常, 1-用户A删除,群组:0-正常, 1-被删除',
  `created` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_smallId_bigId_status_updated` (`smallId`,`bigId`,`status`,`updated`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
4. test_relationmodel.cpp
//
//  test_relationmodel.cpp
//  test_relationmodel
//
//  Created by blueBling on 22-04-06.
//  Copyright (c) 2022年blueBling. All rights reserved.
//

#include "RelationModel.h"


#include<iostream>


using std::cout;
using std::endl;

//从mysql IMRelationShip表中获取用户id为1和17关系记录所在id
int test_getrelationid() {

	uint32_t id = CRelationModel::getInstance()->getRelationId(1, 17, false);

	cout << id << endl;

	return 0;
}


int main(){

	test_getrelationid();


	//这里mysql和redis连接池未释放存在内存泄漏问题,解决方法参考test_dbpool
	
	return 0;
}
5. 源码

链接:TeamTalk_BlueBling

测试demo: tests/test_relationmodel.cpp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值