This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/data/model/message.py
2017-01-18 16:55:32 -05:00

24 lines
782 B
Python

from data.database import Messages, MediaType
def get_messages():
"""Query the data base for messages and returns a container of database message objects"""
return Messages.select(Messages, MediaType).join(MediaType)
def create(messages):
"""Insert messages into the database."""
inserted = []
for message in messages:
severity = message['severity']
media_type_name = message['media_type']
media_type = MediaType.get(name=media_type_name)
inserted.append(Messages.create(content=message['content'], media_type=media_type,
severity=severity))
return inserted
def delete_message(uuids):
"""Delete message from the database"""
if not uuids:
return
Messages.delete().where(Messages.uuid << uuids).execute()