func setup(t *testing.T) *gocql.Session { flag.Set("config", "../config.toml") core.NewConfig() // if err != nil { // t.Fatal(err.Error()) // } session := core.NewCassandraWConn() //create table /*if err := session.Query(`CREATE TABLE IF NOT EXISTS message (owner varchar, sender varchar, id timeuuid, payload varchar, PRIMARY KEY ((owner, sender),id)) WITH CLUSTERING ORDER BY (id DESC)`).Exec(); err != nil { t.Log("can not create table message") t.Fatal(err.Error()) }*/ return session }
func AddMessage(msg *Message, payload string) error { session := core.NewCassandraWConn() return session.Query(addMessage, msg.Receiver, msg.Sender, msg.SenderMessageId, payload).Exec() }
func DeleteChatList(chatId string, owner string, chatType int) error { session := core.NewCassandraWConn() return session.Query(removeChat, chatId, chatId, owner, chatType).Exec() }
func UpdateChatLastMessageId(chatId string, lastMessageId string, owner string, chatType int) error { session := core.NewCassandraWConn() return session.Query(updateChatLastMessageId, lastMessageId, owner, chatType).Exec() }
func CreateChat(chatId string, target string, owner string, chatType int) error { session := core.NewCassandraWConn() return session.Query(createChat, chatId, target, owner, chatType).Exec() }