This commit is contained in:
2025-10-13 18:34:48 +08:00
commit 37865d041f
116 changed files with 31168 additions and 0 deletions

68
odb/chat_session.hxx Normal file
View File

@ -0,0 +1,68 @@
#pragma once
#include <string>
#include <cstddef>
#include <odb/nullable.hxx>
#include <odb/core.hxx>
#include "chat_session_member.hxx"
namespace bite_im {
enum class ChatSessionType {
SINGLE = 1,
GROUP = 2
};
#pragma db object table("chat_session")
class ChatSession {
public:
ChatSession(){}
ChatSession(const std::string &ssid,
const std::string &ssname, const ChatSessionType sstype):
_chat_session_id(ssid),
_chat_session_name(ssname),
_chat_session_type(sstype){}
std::string chat_session_id() const { return _chat_session_id; }
void chat_session_id(std::string &ssid) { _chat_session_id = ssid; }
std::string chat_session_name() const { return _chat_session_name; }
void chat_session_name(std::string &ssname) { _chat_session_name = ssname; }
ChatSessionType chat_session_type() const { return _chat_session_type; }
void chat_session_type(ChatSessionType val) { _chat_session_type = val; }
private:
friend class odb::access;
#pragma db id auto
unsigned long _id;
#pragma db type("varchar(64)") index unique
std::string _chat_session_id;
#pragma db type("varchar(64)")
std::string _chat_session_name;
#pragma db type("tinyint")
ChatSessionType _chat_session_type; //1-单聊; 2-群聊
};
// 这里条件必须是指定条件: css::chat_session_type==1 && csm1.user_id=uid && csm2.user_id != csm1.user_id
#pragma db view object(ChatSession = css)\
object(ChatSessionMember = csm1 : css::_chat_session_id == csm1::_session_id)\
object(ChatSessionMember = csm2 : css::_chat_session_id == csm2::_session_id)\
query((?))
struct SingleChatSession {
#pragma db column(css::_chat_session_id)
std::string chat_session_id;
#pragma db column(csm2::_user_id)
std::string friend_id;
};
// 这里条件必须是指定条件: css::chat_session_type==2 && csm.user_id=uid
#pragma db view object(ChatSession = css)\
object(ChatSessionMember = csm : css::_chat_session_id == csm::_session_id)\
query((?))
struct GroupChatSession {
#pragma db column(css::_chat_session_id)
std::string chat_session_id;
#pragma db column(css::_chat_session_name)
std::string chat_session_name;
};
}

View File

@ -0,0 +1,32 @@
#pragma once
#include <string>
#include <cstddef>
#include <odb/core.hxx>
namespace bite_im {
#pragma db object table("chat_session_member")
class ChatSessionMember {
public:
ChatSessionMember(){}
ChatSessionMember(const std::string& ssid, const std::string &uid)
:_session_id(ssid), _user_id(uid) {}
~ChatSessionMember(){}
std::string session_id() const {return _session_id; }
void session_id(std::string &ssid) { _session_id = ssid; }
std::string user_id() const { return _user_id; }
void user_id(std::string &uid) {_user_id = uid; }
private:
friend class odb::access;
#pragma db id auto
unsigned long _id;
#pragma db type("varchar(64)") index
std::string _session_id;
#pragma db type("varchar(64)")
std::string _user_id;
};
}
//odb -d mysql --generate-query --generate-schema --profile boost/date-time person.hxx

34
odb/friend_apply.hxx Normal file
View File

@ -0,0 +1,34 @@
#pragma once
#include <string>
#include <cstddef>
#include <odb/core.hxx>
namespace bite_im {
#pragma db object table("friend_apply")
class FriendApply{
public:
FriendApply() {}
FriendApply(const std::string &eid,
const std::string &uid, const std::string &pid):
_user_id(uid), _peer_id(pid), _event_id(eid){}
std::string event_id() const { return _event_id; }
void event_id(std::string &eid) { _event_id = eid; }
std::string user_id() const { return _user_id; }
void user_id(std::string &uid) { _user_id = uid; }
std::string peer_id() const { return _peer_id; }
void peer_id(std::string &uid) { _peer_id = uid; }
private:
friend class odb::access;
#pragma db id auto
unsigned long _id;
#pragma db type("varchar(64)") index unique
std::string _event_id;
#pragma db type("varchar(64)") index
std::string _user_id;
#pragma db type("varchar(64)") index
std::string _peer_id;
};
}

83
odb/message.hxx Normal file
View File

@ -0,0 +1,83 @@
#pragma once
#include <string>
#include <cstddef>
#include <odb/nullable.hxx>
#include <odb/core.hxx>
#include <boost/date_time/posix_time/posix_time.hpp>
namespace bite_im {
#pragma db object table("message")
class Message {
public:
Message(){}
Message(const std::string &mid,
const std::string &ssid,
const std::string &uid,
const unsigned char mtype,
const boost::posix_time::ptime &ctime):
_message_id(mid), _session_id(ssid),
_user_id(uid), _message_type(mtype),
_create_time(ctime){}
std::string message_id() const { return _message_id; }
void message_id(const std::string &val) { _message_id = val; }
std::string session_id() const { return _session_id; }
void session_id(const std::string &val) { _session_id = val; }
std::string user_id() const { return _user_id; }
void user_id(const std::string &val) { _user_id = val; }
unsigned char message_type() const { return _message_type; }
void message_type(unsigned char val) { _message_type = val; }
boost::posix_time::ptime create_time() const { return _create_time; }
void create_time(const boost::posix_time::ptime &val) { _create_time = val; }
std::string content() const {
if (!_content) return std::string();
return *_content;
}
void content(const std::string &val) { _content = val; }
std::string file_id() const {
if (!_file_id) return std::string();
return *_file_id;
}
void file_id(const std::string &val) { _file_id = val; }
std::string file_name() const {
if (!_file_name) return std::string();
return *_file_name;
}
void file_name(const std::string &val) { _file_name = val; }
unsigned int file_size() const {
if (!_file_size) return 0;
return *_file_size;
}
void file_size(unsigned int val) { _file_size = val; }
private:
friend class odb::access;
#pragma db id auto
unsigned long _id;
#pragma db type("varchar(64)") index unique
std::string _message_id;
#pragma db type("varchar(64)") index
std::string _session_id; //所属会话ID
#pragma db type("varchar(64)")
std::string _user_id; //发送者用户ID
unsigned char _message_type; //消息类型 0-文本1-图片2-文件3-语音
#pragma db type("TIMESTAMP")
boost::posix_time::ptime _create_time; //消息的产生时间
//可空信息字段
odb::nullable<std::string> _content; //文本消息内容--非文本消息可以忽略
#pragma db type("varchar(64)")
odb::nullable<std::string> _file_id; //文件消息的文件ID -- 文本消息忽略
#pragma db type("varchar(128)")
odb::nullable<std::string> _file_name; //文件消息的文件名称 -- 只针对文件消息有效
odb::nullable<unsigned int> _file_size; //文件消息的文件大小 -- 只针对文件消息有效
};
//odb -d mysql --std c++11 --generate-query --generate-schema --profile boost/date-time message.hxx
}

30
odb/relation.hxx Normal file
View File

@ -0,0 +1,30 @@
#pragma once
#include <string>
#include <cstddef>
#include <odb/nullable.hxx>
#include <odb/core.hxx>
namespace bite_im {
#pragma db object table("relation")
class Relation {
public:
Relation(){}
Relation(const std::string &uid, const std::string &pid):
_user_id(uid), _peer_id(pid){}
std::string user_id() const { return _user_id; }
void user_id(std::string &uid) { _user_id = uid; }
std::string peer_id() const { return _peer_id; }
void peer_id(std::string &uid) { _peer_id = uid; }
private:
friend class odb::access;
#pragma db id auto
unsigned long _id;
#pragma db type("varchar(64)") index
std::string _user_id;
#pragma db type("varchar(64)")
std::string _peer_id;
};
//odb -d mysql --std c++11 --generate-query --generate-schema --profile boost/date-time person.hxx
}

71
odb/user.hxx Normal file
View File

@ -0,0 +1,71 @@
#pragma once
#include <string>
#include <cstddef>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <odb/nullable.hxx>
#include <odb/core.hxx>
typedef boost::posix_time::ptime ptime;
#pragma db object table("user")
class User
{
public:
User(){}
//用户名--新增用户 -- 用户ID, 昵称,密码
User(const std::string &uid, const std::string &nickname, const std::string &password):
_user_id(uid), _nickname(nickname), _password(password){}
//手机号--新增用户 -- 用户ID, 手机号, 随机昵称
User(const std::string &uid, const std::string &phone):
_user_id(uid), _nickname(uid), _phone(phone){}
void user_id(const std::string &val) { _user_id = val; }
std::string user_id() { return _user_id; }
std::string nickname() {
if (_nickname) return *_nickname;
return std::string();
}
void nickname(const std::string &val) { _nickname = val; }
std::string description() {
if (!_description) return std::string();
return *_description;
}
void description(const std::string &val) { _description = val; }
std::string password() {
if (!_password) return std::string();
return *_password;
}
void password(const std::string &val) { _password = val; }
std::string phone() {
if (!_phone) return std::string();
return *_phone;
}
void phone(const std::string &val) { _phone = val; }
std::string avatar_id() {
if (!_avatar_id) return std::string();
return *_avatar_id;
}
void avatar_id(const std::string &val) { _avatar_id = val; }
private:
friend class odb::access;
#pragma db id auto
unsigned long _id;
#pragma db index
std::string _user_id;
odb::nullable<std::string> _nickname; //用户昵称,不一定存在
#pragma db index
odb::nullable<std::string> _description; //用户签名 不一定存在
odb::nullable<std::string> _password; //用户密码 不一定存在
#pragma db index
odb::nullable<std::string> _phone; //用户手机号 不一定存在
odb::nullable<std::string> _avatar_id; //用户头像文件id 不一定存在
};
//odb -d mysql --std c++11 --generate-query --generate-schema --profile boost/date-time person.hxx