Example #1
0
 def find_by_recipient(cursor, recipient_username):
     sql = "SELECT id, from_user, to_user, context, created_at FROM messages WHERE to_user=%s"
     ret = []
     cursor.execute(sql, (recipient_username, ))
     for row in cursor.fetchall():
         loaded_message = Message()
         loaded_message._id = row[0]
         loaded_message.from_user = row[1]
         loaded_message.to_user = row[2]
         loaded_message.context = row[3]
         loaded_message.created_at = row[4]
         ret.append(loaded_message)
     return ret
 def load_all_msg(cursor):
     sql = "SELECT * FROM messages"
     ret = []
     cursor.execute(sql)
     for row in cursor.fetchall():
         loaded_msg = Message()
         loaded_msg._id = row[0]
         from_user_temp = UserService.find_by_id(cursor, row[1])
         loaded_msg.from_user = from_user_temp.username
         to_user_temp = UserService.find_by_id(cursor, row[2])
         loaded_msg.to_user = to_user_temp.username
         loaded_msg.context = row[3]
         loaded_msg.created_at = row[4]
         ret.append(loaded_msg)
     return ret
 def find_by_recipient(cursor, recipient_username):
     sql = "SELECT id, from_user, to_user, context, created_at FROM messages WHERE to_user=%s"
     ret = []
     cursor.execute(sql, (recipient_username, ))
     data = cursor.fetchall()
     if data:
         for row in data:
             loaded_msg = Message()
             loaded_msg._id = row[0]
             from_user_temp = UserService.find_by_id(cursor, row[1])
             loaded_msg.from_user = from_user_temp.username
             to_user_temp = UserService.find_by_id(cursor, row[2])
             loaded_msg.to_user = to_user_temp.username
             loaded_msg.context = row[3]
             loaded_msg.created_at = row[4]
             ret.append(loaded_msg)
         return ret
     else:
         return None