NoSQL的CURD结构体的定义
flyfish 2015-7-23
在这里document部分使用json表示 使用boost::property_tree解析
#pragma once #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> struct MsgHeader { int messageLength; int requestID; int responseTo; int opCode; }; //操作类型 主要是增删改查 enum Operations { dbUpdate = 2001, dbInsert = 2002, dbQuery = 2003, dbDelete = 2004 }; const char * opToString( int op ) { switch ( op ) { case 0: return "none"; case dbUpdate: return "update"; case dbInsert: return "insert"; case dbQuery: return "query"; case dbDelete: return "remove"; default: // 输出异常信息 cannot translate opcode return ""; } } typedef boost::property_tree::ptree ObjectNotation; struct OP_UPDATE { MsgHeader header; int ZERO; string ObjectName; int flags; ObjectNotation selector; ObjectNotation update; }; //selector {ID:1} //update {key1:"value1",key2:"value2"} //相当于SQL UPDATE ObjectName SET key1=value1,key2=value2 WHERE ID=1 struct OP_INSERT { MsgHeader header; int flags; string ObjectName; ObjectNotation* ObjectNotations; }; //ObjectNotations { ID:1, key1:value1, key2:value2 } //相当于SQL INSERT INTO ObjectName(ID,key1,key2)VALUES (1,value1,value2) struct OP_QUERY { MsgHeader header; int flags; string ObjectName ; int numberToSkip; int numberToReturn; ObjectNotation query; ObjectNotation returnFieldsSelector; }; //query { ID: "1 }, //returnFieldsSelector { ID: 1, Name: 1} //相当于SQL SELECT ID, Name FROM ObjectName WHERE ID=1 struct OP_DELETE { MsgHeader header; int ZERO; string ObjectName ; int flags; ObjectNotation selector; }; //selector { ID: "1" } //相当于SQL DELETE FROM ObjectName WHERE ID = 1