def relationByFollowingIdAndFollowerId(following_id, follower_id): cursor.execute( 'SELECT * FROM relation WHERE following_id = %s AND follower_id = %s', ( following_id, follower_id, )) r = cursor.fetchone() return r
def userIdByEmailPassword(email, password): cursor.execute( "SELECT user_id FROM users WHERE email = %s AND password = crypt(%s, password);", ( email, password, )) u = cursor.fetchone() if u is None: return None return u
def userFollow(following_id, follower_id): cursor.execute( 'SELECT * FROM relation WHERE following_id = %s AND follower_id = %s', (following_id, follower_id)) if cursor.fetchone() is None and following_id != follower_id: c_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') cursor.execute( "INSERT INTO relation(following_id, follower_id, c_time) VALUES(%s,%s,%s);", (following_id, follower_id, c_time)) conn.commit() cursor.execute("SELECT nickname FROM users WHERE user_id = %s;", (following_id, )) return ""
def userByEmail(email): cursor.execute("SELECT * FROM users where email = %s;", (email, )) u = cursor.fetchone() return u
def userByUserId(user_id): cursor.execute("SELECT * FROM users where user_id = %s;", (user_id, )) u = cursor.fetchone() return u
def likeMsgCountLike(msg_id): cursor.execute("SELECT COUNT(*) AS count FROM like_msg where msg_id = %s;", (msg_id, )) like_num = cursor.fetchone() return like_num['count']
def likeMsgCount(): cursor.execute("SELECT COUNT(*) AS count FROM like_msg") nb = cursor.fetchone() if nb is None: return 0 return nb['count']
def messageCount(): cursor.execute("SELECT COUNT(*) AS count FROM message") nb = cursor.fetchone() if nb is None: return 0 return nb['count']
def likeCmtCountLike(cmt_id): cursor.execute("SELECT COUNT(*) AS count FROM like_cmt where cmt_id = %s;", (cmt_id, )) like_num = cursor.fetchone() return like_num['count']
def likeCmtGetOne(cmt_id, user_id): cursor.execute("SELECT * FROM like_cmt where cmt_id = %s AND user_id = %s", (cmt_id, user_id)) like = cursor.fetchone() return like
def CommentCountCmt(msg_id): cursor.execute("SELECT COUNT(*) AS count FROM comment where msg_id = %s;", (msg_id, )) like_num = cursor.fetchone() return like_num['count']
def commentCount(): cursor.execute("SELECT COUNT(*) AS count FROM comment") nb = cursor.fetchone() if nb is None: return 0 return nb['count']
def commentByCmtId(cmt_id): cursor.execute("SELECT * FROM comment where cmt_id = %s;", (cmt_id, )) cmt = cursor.fetchone() return cmt
def userByNickname(nickname): cursor.execute("SELECT * FROM users where nickname = %s;", (nickname, )) u = cursor.fetchone() return u
def likeMsgGetOne(msg_id, user_id): cursor.execute("SELECT * FROM like_msg where msg_id = %s AND user_id = %s", (msg_id, user_id)) like = cursor.fetchone() return like
def countcmt(msg_id): cursor.execute("SELECT COUNT(*) FROM comment where msg_id = %s;", (msg_id, )) like_num = cursor.fetchone() return like_num[0]
def messageById(msg_id): cursor.execute("SELECT * FROM message where msg_id = %s;", (msg_id, )) m = cursor.fetchone() return m