当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.query方法代码示例

本文整理汇总了Python中app.model.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app.model.DBSession的用法示例。


在下文中一共展示了DBSession.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testReagentRegistration

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
 def testReagentRegistration(self):
     """Authenticated users can register reagents"""
     numBeforeDbLots = len(DBSession.query(ReagentLot).all())
     self.doRegistration('reagents', 'app/tests/data/molregtest.sdf')
     self.checkGridPostReg('reagents')
     numAfterDbLots = len(DBSession.query(ReagentLot).all())
     ok_(numAfterDbLots == numBeforeDbLots + 2, 'Failed to register 2 new lots')
开发者ID:aytsai,项目名称:ricebowl,代码行数:9,代码来源:test_modreg_registration.py

示例2: testReagentMolStereoReg

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
 def testReagentMolStereoReg(self):
     """Different stereoisomers can be registered as individual molecules"""
     numBeforeDbMols = len(DBSession.query(ReagentMol).all())
     self.doRegistration('reagents', 'app/tests/data/stereo_test.sdf')
     self.checkGridPostReg('reagents')
     numAfterDbMols = len(DBSession.query(ReagentMol).all())
     # We register 11 molecules, but only 10 distinct lots.  One of the molecules is present twice
     # in the sd file.  That molecule is drawn as enantiomers but without the chiral flag set, so that
     # the molecules are treated as being relative stereochemistry and consequently the same.
     # So: We should only see 10 new lots here.
     log.debug('num after db mols is ' + str(numAfterDbMols))
     ok_(numAfterDbMols == numBeforeDbMols + 10, 'Failed to register 10 new stereo mols')
开发者ID:aytsai,项目名称:ricebowl,代码行数:14,代码来源:test_modreg_registration.py

示例3: test_concat

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
    def test_concat(self):
        user = DBSession.query(User).filter(User.id == "d09b9111-70a0-43c0-9373-aba10f2af592").all()[0]

        # balanceQuery = DBSession.query(func.sum(Transaction.amount).label("balance")).with_parent(user).\
        # filter(Transaction.date > datetime.utcnow())

        tags = DBSession.query(Tag).with_parent(user).filter(Tag.type == Tag.TYPE_INCOME)
        balances = []
        # for tag in tags:
        balance = DBSession.query(Transaction.id, func.sum(Transaction.amount).label("balance")).with_parent(user)
        balances = DBSession.query(Tag.name, balance.c.balance). \
            filter(Transaction.incomeTagGroup.has(TagGroup.tags.any(Tag.id == balance)))
        balances.append(balances)

        print(balances)
开发者ID:MarekSalat,项目名称:Trine,代码行数:17,代码来源:_test_tag.py

示例4: getContacts

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
def getContacts():
    users = DBSession.query(User).all()
    retVal = [dict(id=_InnectusUser.user_id,value=_InnectusUser.user_name)]
    for user in users:
        retVal.append(dict(id=user.user_id,value=user.user_name))
     
    return retVal
开发者ID:aytsai,项目名称:ricebowl,代码行数:9,代码来源:messages.py

示例5: test_user

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
    def test_user(self):
        db = DBSession()
        user = db.query(User) \
            .filter(User.password == User.encryptPassword('root'), User.email == r'[email protected]') \
            .one()

        self.assertIsNotNone(user)
开发者ID:MarekSalat,项目名称:Trine,代码行数:9,代码来源:_test_tag.py

示例6: gridUpdate

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
 def gridUpdate(self, modelObjects, row):
     o=modelObjects[Group]
     dbgroup = DBSession.query(Group).get(int(o.group_id))
     if dbgroup.group_name =='admin':
         raise ClientException("You can't change the " + dbgroup.group_name + " group's information.")
     d=DBSession().merge(o)
     return d,
开发者ID:aytsai,项目名称:ricebowl,代码行数:9,代码来源:grids.py

示例7: loadFeedDict

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
 def loadFeedDict(cls, feeds):
     for feed in feeds:
         guid = feed["id"]
         try:
             message = DBSession.query(Message).filter(Message.guid == guid).one()
             if _compareTime(message.updated.timetuple(),feed["updated_parsed"]) < 0:
                 message.update(title=feed["title"],
                                link=feed["link"],
                                updated=feed["updated"],
                                text=feed["summary"])
                 userMessages = DBSession.query(UserMessage).filter(UserMessage.message == message.message_id).all()
                 for userMessage in userMessages:
                     userMessage.new = True
         except NoResultFound:
             message = Message(text=feed["summary"], guid=feed["id"], **feed)
             DBSession.add(message)
             DBSession.flush()
             cls.sendMessageToAllUsers(message)
开发者ID:aytsai,项目名称:ricebowl,代码行数:20,代码来源:messages.py

示例8: test_deref

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
    def test_deref(self):
        trans = DBSession.query(Transaction).options(
            subqueryload(Transaction.incomeTagGroup).subqueryload(TagGroup.tags),
            subqueryload(Transaction.expenseTagGroup).subqueryload(TagGroup.tags)
        ).options(defer('_user_id'))

        tran = trans.first()
        print(tran)
        print(json.dumps({'fsd': tran.incomeTagGroup.tags[0]}))
开发者ID:MarekSalat,项目名称:Trine,代码行数:11,代码来源:_test_tag.py

示例9: getUserMessagesById

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
 def getUserMessagesById(cls, userId, newOnly = False):
     messages = []
     userMessages = DBSession.query(UserMessage).filter(UserMessage.user == userId)
     if newOnly:
         userMessages = userMessages.filter(UserMessage._new == 1)
     userMessages = userMessages.all()
     for userMessage in userMessages:
         messages.append(userMessage.toDict())
     return messages
开发者ID:aytsai,项目名称:ricebowl,代码行数:11,代码来源:messages.py

示例10: sendMessageToUser

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
 def sendMessageToUser(cls, message, userId):
     if str(userId) == "#":
         user = _InnectusUser
         _sendMessageViaMail(message, user)
     else:
         user = DBSession.query(User).filter(User.user_id == userId).one()
         #_sendMessageViaMail(message, user)
         userMessage = cls(user, message)
         DBSession.add(userMessage)
开发者ID:aytsai,项目名称:ricebowl,代码行数:11,代码来源:messages.py

示例11: _setMol

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
 def _setMol(self,molId,mol,smiles,chirality='A'):
         molDb=DBSession.query(self.ModelClass).get(int(molId)) 
         try:
             molDb.mol_struct = mol.encode('utf-8')
             molDb.chirality=chirality 
             transaction.commit()
         except IntegrityError,e:
             transaction.abort()
             log.exception(e)
             raise Exception("Unique field has been violated")
开发者ID:aytsai,项目名称:ricebowl,代码行数:12,代码来源:mol.py

示例12: test_some

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
    def test_some(self):
        # fields = exclude_fields(Transaction, [Transaction.user, Transaction._user_id, Transaction.expenseTagGroup_id, Transaction.incomeTagGroup_id, Transaction.expenseTagGroup, Transaction.incomeTagGroup])
        transactions = DBSession.query(Transaction).options(
            subqueryload(Transaction.incomeTagGroup).subqueryload(TagGroup.tags),
            subqueryload(Transaction.expenseTagGroup).subqueryload(TagGroup.tags)
        ).all()

        transaction_json = jsonify.encode(dict(transactions=transactions))
        parsed = json.loads(transaction_json)
        print(json.dumps(parsed, indent=2, sort_keys=True), len(transactions))
开发者ID:MarekSalat,项目名称:Trine,代码行数:12,代码来源:_test_tag.py

示例13: toDict

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
 def toDict(self):
     mainMessage = DBSession.query(Message).filter(Message.message_id == self.message).one()
     author = mainMessage.author
     return dict(isNew=self.new,
                 id=self.id,
                 title=mainMessage.title, 
                 text=mainMessage.text, 
                 link=mainMessage.link,
                 updated=mainMessage.updated,
                 priority=mainMessage.priority,
                 author=dict(display_name=author.display_name,
                             email_address=author.email_address,
                             user_id=author.user_id))
开发者ID:aytsai,项目名称:ricebowl,代码行数:15,代码来源:messages.py

示例14: test_tag

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
    def test_tag(self):
        db = DBSession()

        res = db.query(func.sum(Transaction.amount).label("balance"))
        print(res.one().balance)
        print(res.filter(Transaction.amount < 0).one().balance)
        print(res.filter(Transaction.amount > 0).one().balance)

        res = db.query(Transaction) \
            .filter(Transaction.expenseTagGroup.has(TagGroup.tags.any(Tag.name.in_(["traveling", "grocery"])))) \
            .filter(Transaction.incomeTagGroup.has(TagGroup.tags.any(Tag.name.in_(["cash"]))))

        print("\n\nAll transactions with expense tags [traveling or grocery] and income tag [cash]\n")
        for r in res.all():
            print(r)

        print("\n\nAll expenses per tag\n")
        for tag in db.query(Tag).filter(Tag.type == Tag.TYPE_EXPENSE):
            print(tag.name)
            for transactions in [group.expenses.all() for group in tag.groups]:
                for transaction in transactions:
                    print(transaction)
开发者ID:MarekSalat,项目名称:Trine,代码行数:24,代码来源:_test_tag.py

示例15: setUp

# 需要导入模块: from app.model import DBSession [as 别名]
# 或者: from app.model.DBSession import query [as 别名]
    def setUp(self):
        super(TestStructureSearch,self).setUp()
        org=DBSession.query(ReagentVendor).first()
        for name, smiles in self.smilesToReg.items():
            mol = ReagentMol(toMolFromSmiles(smiles))
            mol.mol_name = name
            submitter = User.by_user_name('chemadmin')
            lot = ReagentLot()
            lot.lot_submitter_id = submitter.user_id
            lot.lot_source_org_id = org.vendor_id
            mol.addLot(lot, 0)

            DBSession.add(mol)
            DBSession.flush()
开发者ID:aytsai,项目名称:ricebowl,代码行数:16,代码来源:test_struct_search.py


注:本文中的app.model.DBSession.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。