数据库以表为载体存储数据,不同的表往往示意不同的实体。作为国产自研键值型nosql数据库,TcaplusDB反对2种类型的表:protobuf(Protocol Buffers)表和TDR(Tencent Data Representation)表。
Protobuf是Google开发的一种描述性语言,对结构化数据进行序列化,同时强调简略性和性能; TDR是由腾讯开发的跨平台数据表示语言,联合了XML,二进制和ORM(对象关系映射)的劣势,在腾讯游戏数据的序列化场景中宽泛应用。本文将简略介绍如何定义这两种表。
Protobuf表以下是protobuf表game_players.proto的示例,您能够将文件上传到腾讯云控制台并创立该表。
syntax = "proto3"; // 指定protobuf语言版本,proto3.// 导入TcaplusDB公共定义服务 import "tcaplusservice.optionv1.proto"; message game_players { // 定义TcaplusDB表,蕴含message类型// 基于选择项tcaplusservice.tcaplus_primary_key创立主键字段// TcaplusDB单个表最多能指定4个主键字段 option(tcaplusservice.tcaplus_primary_key) = "player_id, player_name, player_email"; // 基于选择项tcaplusservice.tcaplus_index创立主键索引 option(tcaplusservice.tcaplus_index) = "index_1(player_id, player_name)"; option(tcaplusservice.tcaplus_index) = "index_2(player_id, player_email)"; // TcaplusDB反对的数值类型: // int32, int64, uint32, uint64, sint32, sint64, bool, fixed64, sfixed64, double, fixed32, sfixed32, float, string, bytes // 嵌套类型: message // 主键字段 int64 player_id = 1; string player_name = 2; string player_email = 3; // 一般(非主键) 字段 int32 game_server_id = 4; repeated string login_timestamp = 5; repeated string logout_timestamp = 6; bool is_online = 7; payment pay = 8; }message payment { int64 pay_id = 1;uint64 amount = 2;int64 method = 3;}TDR表TDR反对通用(generic)表和列表(list)表。 generic表是以表的模式示意元素属性的表,例如学生,雇主,游戏玩家表。 list表是一系列记录,例如游戏排行榜,游戏中的邮件(通常是最近的100封邮件)。
...