Ejemplo n.º 1
0
    def find_by_receiver_id(self, receiver_id: str) -> Tuple[Message or None, bool]:
        try:
            self.controller_database.run_query_with_args(
                f'''
                    SELECT * from {self.table_name} where receiver_id = :id
                ''',
                {"id": receiver_id}
            )

            result = self.controller_database.fetch_one_result_from_last_query()

            if result:
                message = Message(*result)
                return message, True

        except Exception as exp:
            print(f"Could not find message with receiver_id {receiver_id}")
            print(repr(exp))

        return None, False
Ejemplo n.º 2
0
    def find_all_by_receiver_id(self, receiver_id: str) -> Tuple[List[Message], bool]:
        try:
            self.controller_database.run_query_with_args(
                f'''
                        SELECT * from {self.table_name} where receiver_id = :id
                    ''',
                {"id": receiver_id}
            )

            result = self.controller_database.fetch_all_results_from_last_query()
            message_list: List[Message] = []

            for rows in result:
                message_list.append(Message(*rows))

            return message_list, True

        except Exception as exp:
            print(f"Could not find messages with receiver_id {receiver_id}")
            print(repr(exp))

        return [], False