Example #1
0
    def create(cls, wsme_entry):
        session = db_session.get_session(sqlite_fk=True)
        with session.begin():
            db_entry = convert_to_db_model(cls, wsme_entry, session)
            session.add(db_entry)

        return cls.get(id=db_entry.id)
Example #2
0
    def update(cls, key_property_name="id", key_property_value=None,
               wsme_entry=None):
        db_entry = cls.from_db(**{key_property_name: key_property_value})\
            .first()

        session = db_session.get_session(sqlite_fk=True)
        with session.begin():
            updated_db_model = update_db_model(cls, db_entry, wsme_entry)
            session.add(updated_db_model)

        return cls.get(id=db_entry.id)
Example #3
0
 def save(self, session=None):
     """Save this object."""
     if not session:
         session = sa.get_session()
     # NOTE(boris-42): This part of code should be look like:
     #                       sesssion.add(self)
     #                       session.flush()
     #                 But there is a bug in sqlalchemy and eventlet that
     #                 raises NoneType exception if there is no running
     #                 transaction and rollback is called. As long as
     #                 sqlalchemy has this bug we have to create transaction
     #                 explicity.
     with session.begin(subtransactions=True):
         session.add(self)
         session.flush()
Example #4
0
    def from_db(cls, **kwargs):
        model_cls = WSME_TO_SQLALCHEMY[cls]
        session = db_session.get_session(sqlite_fk=True)
        query = session.query(model_cls)

        return query.filter_by(**kwargs)