Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlee0201 committed Oct 5, 2017
1 parent 13055af commit be0730f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 44 deletions.
32 changes: 22 additions & 10 deletions mars/stn/mqtt/DB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ namespace mars {
namespace stn {

static const std::string DB_NAME = "data";
static const std::string VERSION_TABLE_NAME = "version";
static const std::string VERSION_COLUMN_VERSION = "_version";

const std::string VERSION_TABLE_NAME = "t_version";
const std::string VERSION_COLUMN_VERSION = "_version";

const std::string MESSAGE_TABLE_NAME = "t_message";
const std::string USER_TABLE_NAME = "t_user";
const std::string GROUP_TABLE_NAME = "t_group";
const std::string GROUP_MEMBER_TABLE_NAME = "t_group_member";
const std::string TIMELINE_TABLE_NAME = "t_timeline";
const std::string CONVERSATION_TABLE_NAME = "t_conversation";


DB* DB::instance_ = NULL;

DB* DB::Instance() {
Expand Down Expand Up @@ -260,7 +270,7 @@ namespace mars {
WCDB::ColumnDef(Column("_uid"), ColumnType::Integer64).makeDefault(0),
WCDB::ColumnDef(Column("_timestamp"), ColumnType::Integer64).makeDefault(0)
};
_database->exec(WCDB::StatementCreateTable().create("message", messageDefList, true),
_database->exec(WCDB::StatementCreateTable().create(MESSAGE_TABLE_NAME, messageDefList, true),
error);


Expand All @@ -279,7 +289,7 @@ namespace mars {
WCDB::ColumnDef(Column("_extra"), ColumnType::Text),
WCDB::ColumnDef(Column("_update_dt"), ColumnType::Integer64).makeDefault(0)
};
_database->exec(WCDB::StatementCreateTable().create("user", userDefList, true),
_database->exec(WCDB::StatementCreateTable().create(USER_TABLE_NAME, userDefList, true),
error);


Expand All @@ -294,7 +304,9 @@ namespace mars {
WCDB::ColumnDef(Column("_extra"), ColumnType::Text),
WCDB::ColumnDef(Column("_update_dt"), ColumnType::Integer64).makeDefault(0)
};
_database->exec(WCDB::StatementCreateTable().create("group", groupDefList, true),


_database->exec(WCDB::StatementCreateTable().create(GROUP_TABLE_NAME, groupDefList, true),
error);


Expand All @@ -306,18 +318,18 @@ namespace mars {
WCDB::ColumnDef(Column("_type"), ColumnType::Text),
WCDB::ColumnDef(Column("_update_dt"), ColumnType::Integer64).makeDefault(0)
};
_database->exec(WCDB::StatementCreateTable().create("groupMember", groupMemberDefList, true),
_database->exec(WCDB::StatementCreateTable().create(GROUP_MEMBER_TABLE_NAME, groupMemberDefList, true),
error);


//create timeline table
std::list<const WCDB::ColumnDef> timelineDefList = {
WCDB::ColumnDef(Column("_head"), ColumnType::Integer64).makeDefault(0),
};
_database->exec(WCDB::StatementCreateTable().create("timeline", timelineDefList, true),
_database->exec(WCDB::StatementCreateTable().create(TIMELINE_TABLE_NAME, timelineDefList, true),
error);
//set timeline to 0;
WCDB::RecyclableStatement statementHandleTimeline = GetInsertStatement("timeline", {"_head"});
WCDB::RecyclableStatement statementHandleTimeline = GetInsertStatement(TIMELINE_TABLE_NAME, {"_head"});
Bind(statementHandleTimeline, 0, 1);
ExecuteInsert(statementHandleTimeline);

Expand All @@ -330,7 +342,7 @@ namespace mars {
WCDB::ColumnDef(Column("_istop"), ColumnType::Integer32).makeDefault(0),
WCDB::ColumnDef(Column("_timestamp"), ColumnType::Integer64).makeDefault(0)
};
_database->exec(WCDB::StatementCreateTable().create("conversation", convDefList, true),
_database->exec(WCDB::StatementCreateTable().create(CONVERSATION_TABLE_NAME, convDefList, true),
error);

//create conversation index table
Expand All @@ -341,7 +353,7 @@ namespace mars {
};
_database->exec(WCDB::StatementCreateIndex()
.create("conv_index", true, true)
.on("conversation", convIndexList),
.on(CONVERSATION_TABLE_NAME, convIndexList),
error);


Expand Down
11 changes: 11 additions & 0 deletions mars/stn/mqtt/DB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ class Database;
}
namespace mars {
namespace stn {

extern const std::string VERSION_TABLE_NAME;
extern const std::string VERSION_COLUMN_VERSION;

extern const std::string MESSAGE_TABLE_NAME;
extern const std::string USER_TABLE_NAME;
extern const std::string GROUP_TABLE_NAME;
extern const std::string GROUP_MEMBER_TABLE_NAME;
extern const std::string TIMELINE_TABLE_NAME;
extern const std::string CONVERSATION_TABLE_NAME;

class DB {

private:
Expand Down
Loading

0 comments on commit be0730f

Please sign in to comment.