コード例 #1
0
 def get_chr_stat_from_db(self):
     session = global_states.Session()
     char_stat = session.query(CharacterStat).filter(
         CharacterStat._chr_id == self.chr_id).scalar()
     session.expunge_all()
     session.close()
     return char_stat
コード例 #2
0
 def get_cosmetic_look_from_db(self):
     session = global_states.Session()
     cosmetic_look = session.query(CosmeticLook).filter(
         CosmeticLook._id == self.chr_id).scalar()
     session.expunge_all()
     session.close()
     return cosmetic_look
コード例 #3
0
 def get_account_from_db(self):
     session = global_states.Session()
     account = session.query(Account).filter(Account._user_id == self.user_id).scalar()
     session.close()
     if account is not None:
         account.init_characters()
     return account
コード例 #4
0
ファイル: account.py プロジェクト: Bratah123/Spirit
    def init_characters(self):
        """
        Adds all characters from this account into characters list (checks db)
        Returns: void
        -------

        """
        session = global_states.Session()
        characters = session.query(Character).filter(Character._acc_id == self.account_id).all()
        for char in characters:
            char.init_avatar_data()
            self.characters.append(char)
        session.expunge_all()
        session.close()
コード例 #5
0
    async def save(self):
        session = global_states.Session()
        mapped_values = {}

        for item in User.__dict__.items():
            field_name = item[0]
            field_type = item[1]
            is_column = isinstance(field_type, InstrumentedAttribute)
            if is_column:
                mapped_values[field_name] = getattr(self, field_name)

        session.query(User).filter(User._id == self.user_id).update(mapped_values)
        session.commit()
        session.close()
コード例 #6
0
    async def init_in_db(self):
        """
        This function should only be used for newly created characters NOT FOR SAVING
        Returns
        -------

        """
        session = global_states.Session()
        session.add(self)
        session.commit()
        session.refresh(self)
        session.expunge_all()
        session.close()
        self.init_avatar_data()
        return self
コード例 #7
0
    async def get_user_from_name(username: str):
        """

        Parameters
        ----------
        username: username aka "name" in database

        Returns User (itself)
        -------

        """

        session = global_states.Session()
        user = session.query(User).filter(User._name == username).scalar()
        session.close()

        return user
コード例 #8
0
    async def save(self):
        session = global_states.Session()
        mapped_values = {}

        for item in Character.__dict__.items():
            field_name = item[0]
            field_type = item[1]
            is_column = isinstance(field_type, InstrumentedAttribute)
            if is_column:
                mapped_values[field_name] = getattr(self, field_name)

        session.query(Character).filter(Character._id == self.chr_id).update(
            mapped_values, synchronize_session=False)
        session.commit()
        session.close()

        await self.cosmetic_info.cosmetic_look.save()
        await self.cosmetic_info.character_stat.save()
コード例 #9
0
ファイル: character_stat.py プロジェクト: Bratah123/Spirit
 def init_in_db(self):
     session = global_states.Session()
     session.add(self)
     session.commit()
     session.refresh(self)
     session.close()