Example #1
0
 def update_links(self, links, date):
     for link in links:
         if db_session.query(exists().where(Link.link == link[1])).scalar():
             continue
         else:
             self.links.append(Link(*link, self, date))
     db_session.commit()
Example #2
0
 def add_keywords(self, keywords):
     if len(keywords) > 0:
         added = set(self.get_keywords())
         to_add = set(keywords).difference(added)
         for word in to_add:
             self.keywords.append(Keyword.return_or_create(self, word))
         db_session.commit()
Example #3
0
 def add_bills(self, bills):
     for bill in bills:
         if db_session.query(exists().where(Bill.num == bill)).scalar():
             bill_obj = db_session.query(Bill).filter_by(num=bill).first()
             self.bills.append(bill_obj)
         else:
             self.bills.append(Bill(bill))
     db_session.commit()
Example #4
0
def delete(model: M):
    """
    Deletes a model from the database.

    :param model: The model to delete
    """
    db_session.delete(model)
    db_session.commit()
Example #5
0
    def __init__(self, link, typ, bill, date):

        self.typ = typ
        self.link = link
        self.bill_id = bill.id
        self.date = date
        self.download_text()
        db_session.add(self)
        self.add_keywords()
        db_session.commit()
Example #6
0
 def find_new_keyword(self):
     for bill in Bill.query.all():
         if self not in bill.keywords and re.search(
                 fr'.*{self.word}.*',
             (bill.description + bill.authors).replace(" ", "").lower()):
             bill.keywords.append(self)
         for link in bill.links:
             if self not in link.keywords and re.search(
                     fr'.*{self.word}.*',
                     link.text.replace(" ", "").lower()):
                 link.keywords.append(self)
                 if self not in bill.keywords:
                     bill.keywords.append(self)
     db_session.commit()
Example #7
0
def create_all_patients(model: [Patient]):
    """
    add_all list of model into the database.

    All the actual SQL is handled under the hood by SQLAlchemy. However, it's important
    to note that many tables may be modified by this operation: for example, in the case
    of a model which contains relationships to other models.

    Any exceptions thrown by database system are propagated back through this function.

    :param model: The model to insert
    :param refresh: If true, immediately refresh ``model`` populating it with data from
                    the database; this involves an additional query so only use it if
                    necessary
    """
    db_session.add_all(model)
    db_session.commit()
Example #8
0
def update(m: Type[M], changes: dict, **kwargs):
    """
    Applies a series of changes to a model in the database.

    The process for updating a model is as follows:

    * Retrieve the model by querying the database using the supplied ``kwargs`` as
      query parameters
    * Iterate through ``changes`` and update the fields of the model
    * Commit the changes to the database
    * Return the model

    :param m: Type of model to update
    :param changes: A dictionary mapping columns to new values
    :param kwargs: Keyword arguments mapping column names to values to parameterize the
                   query (e.g., ``patientId="abc"``)
    :except sqlalchemy.orm.exc.MultipleResultsFound: If multiple models are found
    :return: The updated model
    """
    model = read(m, **kwargs)
    for k, v in changes.items():
        setattr(model, k, v)
    db_session.commit()
Example #9
0
 def __init__(self, num):
     self.num = num
     self.add_params()
     db_session.add(self)
     db_session.commit()
Example #10
0
 def __init__(self, chat_id):
     self.chat_id = chat_id
     db_session.add(self)
     db_session.commit()
Example #11
0
 def __init__(self, descr, date, bill):
     self.descr = descr
     self.date = date
     self.bill_id = bill.id
     db_session.add(self)
     db_session.commit()
Example #12
0
 def __init__(self, user, word):
     self.word = word.lower().strip()
     self.users.append(user)
     db_session.add(self)
     db_session.commit()
     self.find_new_keyword()
Example #13
0
 def update_date(self, updated_date):
     self.updated_date = updated_date
     db_session.commit()
Example #14
0
 def update_events(self, events, date):
     for event in events:
         self.events.append(Event(event, date, self))
     db_session.commit()