當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。